Browse Source

adding tests for Prompt class, typos

El RIDO 8 years ago
parent
commit
360a0921e2
4 changed files with 42 additions and 4 deletions
  1. 2 2
      js/privatebin.js
  2. 38 0
      js/test.js
  3. 1 1
      tpl/bootstrap.php
  4. 1 1
      tpl/page.php

+ 2 - 2
js/privatebin.js

@@ -1468,7 +1468,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
                 throw 'password prompt canceled';
                 throw 'password prompt canceled';
             }
             }
             if (password.length === 0) {
             if (password.length === 0) {
-                // recursive…
+                // recurse…
                 return me.requestPassword();
                 return me.requestPassword();
             }
             }
 
 
@@ -1476,7 +1476,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
         }
         }
 
 
         /**
         /**
-         * getthe cached password
+         * get the cached password
          *
          *
          * If you do not get a password with this function
          * If you do not get a password with this function
          * (returns an empty string), use requestPassword.
          * (returns an empty string), use requestPassword.

+ 38 - 0
js/test.js

@@ -22,6 +22,7 @@ global.sjcl = require('./sjcl-1.0.6');
 global.Base64 = require('./base64-2.1.9').Base64;
 global.Base64 = require('./base64-2.1.9').Base64;
 global.RawDeflate = require('./rawdeflate-0.5').RawDeflate;
 global.RawDeflate = require('./rawdeflate-0.5').RawDeflate;
 global.RawDeflate.inflate = require('./rawinflate-0.3').RawDeflate.inflate;
 global.RawDeflate.inflate = require('./rawinflate-0.3').RawDeflate.inflate;
+require('./bootstrap-3.3.7');
 require('./privatebin');
 require('./privatebin');
 
 
 // redirect console messages to log file
 // redirect console messages to log file
@@ -1264,3 +1265,40 @@ describe('PasteStatus', function () {
     });
     });
 });
 });
 
 
+describe('Prompt', function () {
+    // TODO: this does not test the prompt() fallback, since that isn't available
+    //       in nodejs -> replace the prompt in the "page" template with a modal
+    describe('requestPassword & getPassword', function () {
+        this.timeout(30000);
+        before(function () {
+            cleanup();
+        });
+
+        jsc.property(
+            'returns the password fed into the dialog',
+            'string',
+            function (password) {
+                password = password.replace(/\r+/g, '');
+                var clean = jsdom('', {url: 'ftp://example.com/#0'});
+                $('body').html(
+                    '<div id="passwordmodal" class="modal fade" role="dialog">' +
+                    '<div class="modal-dialog"><div class="modal-content">' +
+                    '<div class="modal-body"><form id="passwordform" role="form">' +
+                    '<div class="form-group"><input id="passworddecrypt" ' +
+                    'type="password" class="form-control" placeholder="Enter ' +
+                    'password"></div><button type="submit">Decrypt</button>' +
+                    '</form></div></div></div></div><div id="cipherdata">{}</div>'
+                );
+                $.PrivateBin.Model.init();
+                $.PrivateBin.Prompt.init();
+                $.PrivateBin.Prompt.requestPassword();
+                $('#passworddecrypt').val(password);
+                $('#passwordform').submit();
+                var result = $.PrivateBin.Prompt.getPassword();
+                clean();
+                return result == password;
+            }
+        );
+    });
+});
+

+ 1 - 1
tpl/bootstrap.php

@@ -69,7 +69,7 @@ if ($MARKDOWN):
 <?php
 <?php
 endif;
 endif;
 ?>
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-/foCCYtW+1hgr5bCBVfnt2GxFOVEd6p3e3d3Wn4TLeIQy8WI5w8ywxBhxvqjjpOvDNPKoQlIf9Zi7xmEK9IYUQ==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-rDOydUZZZd8/nPpB9EekhSoXRF1ezh7veCT1ImGX6lH2gupGIboh6O7S3I9r/B21ytB22AsbrTBGjZ4ORvpFSQ==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->
 		<![endif]-->

+ 1 - 1
tpl/page.php

@@ -47,7 +47,7 @@ if ($MARKDOWN):
 <?php
 <?php
 endif;
 endif;
 ?>
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-/foCCYtW+1hgr5bCBVfnt2GxFOVEd6p3e3d3Wn4TLeIQy8WI5w8ywxBhxvqjjpOvDNPKoQlIf9Zi7xmEK9IYUQ==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-rDOydUZZZd8/nPpB9EekhSoXRF1ezh7veCT1ImGX6lH2gupGIboh6O7S3I9r/B21ytB22AsbrTBGjZ4ORvpFSQ==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->
 		<![endif]-->