diff options
author | Azul <azul@riseup.net> | 2012-08-04 16:01:05 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2012-08-04 16:01:05 +0200 |
commit | f0b308e4081a4c804da4f7bfbe4802a8999d4c26 (patch) | |
tree | c577b8973320e1e17ab3d3dbe477f2b01c85b0fe /spec | |
parent | 94d1938e2e5d0ee5e8e7b9a8ed44a067677e0133 (diff) |
copied jqueryRest and restful specs from django
no real change yet
Diffstat (limited to 'spec')
-rw-r--r-- | spec/DjangoSpecRunner.html | 4 | ||||
-rw-r--r-- | spec/RestfulSpecRunner.html | 75 | ||||
-rw-r--r-- | spec/django/login.js (renamed from spec/login.js) | 0 | ||||
-rw-r--r-- | spec/django/signup.js (renamed from spec/signup.js) | 0 | ||||
-rw-r--r-- | spec/restful/.login.js.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | spec/restful/.signup.js.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | spec/restful/login.js | 67 | ||||
-rw-r--r-- | spec/restful/signup.js | 59 |
8 files changed, 203 insertions, 2 deletions
diff --git a/spec/DjangoSpecRunner.html b/spec/DjangoSpecRunner.html index 8315c5b..7a39dde 100644 --- a/spec/DjangoSpecRunner.html +++ b/spec/DjangoSpecRunner.html @@ -25,8 +25,8 @@ <!-- include spec files here... --> <script type="text/javascript" src="specHelper.js"></script> - <script type="text/javascript" src="signup.js"></script> - <script type="text/javascript" src="login.js"></script> + <script type="text/javascript" src="django/signup.js"></script> + <script type="text/javascript" src="django/login.js"></script> <script type="text/javascript"> diff --git a/spec/RestfulSpecRunner.html b/spec/RestfulSpecRunner.html new file mode 100644 index 0000000..bc4715f --- /dev/null +++ b/spec/RestfulSpecRunner.html @@ -0,0 +1,75 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> + <title>Jasmine Spec Runner</title> + + <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.1.0.rc1/jasmine_favicon.png"> + + <link rel="stylesheet" type="text/css" href="lib/jasmine/jasmine.css"> + <script type="text/javascript" src="lib/jasmine/jasmine.js"></script> + <script type="text/javascript" src="lib/jasmine/jasmine-html.js"></script> + + <script type="text/javascript" src="lib/sinon/sinon-1.3.4.js"></script> + <script type="text/javascript" src="lib/jasmine-sinon.js"></script> + + <!-- the files we are testing... --> + <script type="text/javascript" src="../lib/SHA256.js"></script> + <script type="text/javascript" src="../lib/prng4.js"></script> + <script type="text/javascript" src="../lib/rng.js"></script> + <script type="text/javascript" src="../lib/jsbn.js"></script> + <script type="text/javascript" src="../lib/jsbn2.js"></script> + <script type="text/javascript" src="../lib/srp.js"></script> + <script type="text/javascript" src="../lib/jqueryRest.js"></script> + <script type="text/javascript" src="../lib/srp_register.js"></script> + + <!-- include spec files here... --> + <script type="text/javascript" src="specHelper.js"></script> + <script type="text/javascript" src="restful/signup.js"></script> + <script type="text/javascript" src="restful/login.js"></script> + + <script type="text/javascript"> + + (function() { + var jasmineEnv = jasmine.getEnv(); + jasmineEnv.updateInterval = 1000; + + var htmlReporter = new jasmine.HtmlReporter(); + + jasmineEnv.addReporter(htmlReporter); + + jasmineEnv.specFilter = function(spec) { + return htmlReporter.specFilter(spec); + }; + + var currentWindowOnload = window.onload; + window.onload = function() { + if (currentWindowOnload) { + currentWindowOnload(); + } + + execJasmine(); + }; + + function execJasmine() { + jasmineEnv.execute(); + } + })(); + + </script> + +</head> + +<body> + <form action="." onsubmit="return register()"> + <table> + <tr><td>Username:</td><td><input type="text" id="srp_username" value="user" /></td></tr> + <tr><td>Password:</td><td><input type="password" id="srp_password" value="opensesami"/></td></tr> + <input type="hidden" id="srp_url" value=""/> + <input type="hidden" id="srp_forward" value="#logged_in"/> + <input type="hidden" id="srp_server" value="django"/> + </table> + <input type="submit"/> + </form> +</body> +</html> diff --git a/spec/login.js b/spec/django/login.js index eea6062..eea6062 100644 --- a/spec/login.js +++ b/spec/django/login.js diff --git a/spec/signup.js b/spec/django/signup.js index b38778a..b38778a 100644 --- a/spec/signup.js +++ b/spec/django/signup.js diff --git a/spec/restful/.login.js.swp b/spec/restful/.login.js.swp Binary files differnew file mode 100644 index 0000000..7a6e842 --- /dev/null +++ b/spec/restful/.login.js.swp diff --git a/spec/restful/.signup.js.swp b/spec/restful/.signup.js.swp Binary files differnew file mode 100644 index 0000000..686174a --- /dev/null +++ b/spec/restful/.signup.js.swp diff --git a/spec/restful/login.js b/spec/restful/login.js new file mode 100644 index 0000000..729f902 --- /dev/null +++ b/spec/restful/login.js @@ -0,0 +1,67 @@ +describe("Login", function() { + + it("has an identify function", function() { + var srp = new SRP(jqueryRest()); + expect(typeof srp.identify).toBe('function'); + }); + + describe("(INTEGRATION)", function (){ + // a valid auth attempt for the user / password given in the spec runner: + var a = 'af141ae6'; + var B = '887005895b1f5528b4e4dfdce914f73e763b96d3c901d2f41d8b8cd26255a75'; + var salt = '5d3055e0acd3ddcfc15'; + var M = 'be6d7db2186d5f6a2c55788479b6eaf75229a7ca0d9e7dc1f886f1970a0e8065' + var M2 = '2547cf26318519090f506ab73a68995a2626b1c948e6f603ef9e1b0b78bf0f7b'; + var A, callback; + + + beforeEach(function() { + this.srp = new SRP(jqueryRest()); + A = this.srp.calculateAndSetA(a); + + specHelper.setupFakeXHR.apply(this); + + this.srp.success = sinon.spy(); + }); + + afterEach(function() { + this.xhr.restore(); + }); + + it("works with XML responses", function(){ + this.srp.identify(); + + this.expectRequest('handshake/', 'I=user&A='+A); + this.respondXML("<r s='"+salt+"' B='"+B+"' />"); + this.expectRequest('authenticate/', 'M='+M); + this.respondXML("<M>"+M2+"</M>"); + + expect(this.srp.success).toHaveBeenCalled(); + }); + + it("works with JSON responses", function(){ + this.srp.identify(); + + this.expectRequest('handshake/', 'I=user&A='+A); + this.respondJSON({s: salt, B: B}); + this.expectRequest('authenticate/', 'M='+M); + this.respondJSON({M: M2}); + + expect(this.srp.success).toHaveBeenCalled(); + }); + + it("rejects B = 0", function(){ + this.srp.error_message = sinon.spy(); + this.srp.identify(); + + this.expectRequest('handshake/', 'I=user&A='+A); + this.respondJSON({s: salt, B: 0}); + // aborting if B=0 + expect(this.requests).toEqual([]); + expect(this.srp.error_message).toHaveBeenCalled(); + }); + }); + + +}); + diff --git a/spec/restful/signup.js b/spec/restful/signup.js new file mode 100644 index 0000000..26e97b5 --- /dev/null +++ b/spec/restful/signup.js @@ -0,0 +1,59 @@ +describe("Signup", function() { + + beforeEach(function() { + this.srp = new SRP(jqueryRest()); + specHelper.setupFakeXHR.apply(this); + }); + + afterEach(function() { + this.xhr.restore(); + }); + + it("has a register function", function() { + expect(typeof this.srp.register).toBe('function'); + }); + + it("fetches a salt from /register/salt", function(){ + var callback = sinon.spy(); + this.srp.register_receive_salt = callback; + this.srp.register(); + this.expectRequest('register/salt/', "I=user") + this.respondXML("<salt>5d3055e0acd3ddcfc15</salt>"); + expect(callback.called).toBeTruthy(); + }); + + it("receives the salt from /register/salt", function(){ + var callback = sinon.spy(); + this.srp.remote.register_send_verifier = callback; + this.srp.register(); + this.expectRequest('register/salt/', "I=user") + this.respondXML("<salt>5d3055e0acd3ddcfc15</salt>"); + expect(callback).toHaveBeenCalledWith("adcd57b4a4a05c2e205b0b7b30014d9ff635d8d8db2f502f08e9b9c132800c44", this.srp.registered_user); + }); + + it("identifies after successful registration (INTEGRATION)", function(){ + var callback = sinon.spy(); + this.srp.identify = callback; + this.srp.register(); + this.expectRequest('register/salt/', "I=user") + this.respondXML("<salt>5d3055e0acd3ddcfc15</salt>"); + this.expectRequest('register/user/', "v=adcd57b4a4a05c2e205b0b7b30014d9ff635d8d8db2f502f08e9b9c132800c44"); + this.respondXML("<ok />"); + expect(callback).toHaveBeenCalled(); + }); + + it("identifies after successful registration with JSON (INTEGRATION)", function(){ + var callback = sinon.spy(); + this.srp.identify = callback; + this.srp.register(); + this.expectRequest('register/salt/', "I=user") + this.respondJSON({salt: "5d3055e0acd3ddcfc15"}); + this.expectRequest('register/user/', "v=adcd57b4a4a05c2e205b0b7b30014d9ff635d8d8db2f502f08e9b9c132800c44"); + this.respondJSON({ok: true}); + expect(callback).toHaveBeenCalled(); + }); + + +}); + + |