summaryrefslogtreecommitdiff
path: root/spec/login_spec.js
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2013-03-20 12:51:56 +0100
committerAzul <azul@riseup.net>2013-03-20 12:51:56 +0100
commit3328b20621265b0c50ed395ea890b267ab89109b (patch)
tree5afee96076bd922653231af818e98d5147457dff /spec/login_spec.js
parent527eb51ad4b943bde7e2ba411f5772611a80463c (diff)
parentd29d1146865d36e9d9789d3936e7a9163511be0a (diff)
Merge branch 'release/0.3.0'
Diffstat (limited to 'spec/login_spec.js')
-rw-r--r--spec/login_spec.js55
1 files changed, 31 insertions, 24 deletions
diff --git a/spec/login_spec.js b/spec/login_spec.js
index 4df62a8..e806cff 100644
--- a/spec/login_spec.js
+++ b/spec/login_spec.js
@@ -1,9 +1,4 @@
-describe("Login", function() {
-
- it("has an identify function", function() {
- var srp = new SRP(jqueryRest());
- expect(typeof srp.identify).toBe('function');
- });
+describe("Login with srp var", function() {
describe("(Compatibility with py-srp)", function (){
// these need to be the same as in the spec runner:
@@ -24,11 +19,9 @@ describe("Login", function() {
beforeEach(function() {
- this.srp = new SRP(jqueryRest());
-
specHelper.setupFakeXHR.apply(this);
- A_ = this.srp.session.calculateAndSetA(a)
+ A_ = srp.session.calculateAndSetA(a)
});
afterEach(function() {
@@ -40,37 +33,51 @@ describe("Login", function() {
});
it("calculates the same verifier", function(){
- expect(this.srp.session.getV().toString(16)).toBe(V);
+ expect(srp.session.getV().toString(16)).toBe(V);
});
it("calculates the same key", function(){
- this.srp.session.calculations(salt, B);
- expect(this.srp.session.key()).toBe(K);
+ srp.session.calculations(salt, B);
+ expect(srp.session.key()).toBe(K);
});
- it("works with JSON responses", function(){
- var success = sinon.spy();
- this.srp.identify(success);
+ it("authenticates successfully", function(){
+ srp.loggedIn = sinon.spy();
+ srp.login();
- this.expectRequest('sessions.json', 'login=' +login+ '&A=' +A, 'POST');
+ this.expectRequest('/sessions.json', 'login=' +login+ '&A=' +A, 'POST');
this.respondJSON({salt: salt, B: B});
- this.expectRequest('sessions/'+login+'.json', 'client_auth='+M, 'PUT');
+ this.expectRequest('/sessions/'+login+'.json', 'client_auth='+M, 'PUT');
this.respondJSON({M2: M2});
- expect(success).toHaveBeenCalled();
+ expect(srp.loggedIn).toHaveBeenCalled();
+ });
+
+ it("reports errors during handshake", function(){
+ srp.error = sinon.spy();
+ var error = {login: "something went wrong on the server side"};
+ srp.login();
+
+ this.expectRequest('/sessions.json', 'login=' +login+ '&A=' +A, 'POST');
+ this.respondJSON(error, 422);
+ //this.expectNoMoreRequests();
+
+ expect(srp.error).toHaveBeenCalled;
+ var args = srp.error.args[0];
+ expect(args[0]).toEqual(error);
});
it("rejects B = 0", function(){
- var success = sinon.spy();
- var error = sinon.spy();
- this.srp.identify(success, error);
+ srp.loggedIn = sinon.spy();
+ srp.error = sinon.spy();
+ srp.login();
- this.expectRequest('sessions.json', 'login=' +login+ '&A=' +A, 'POST');
+ this.expectRequest('/sessions.json', 'login=' +login+ '&A=' +A, 'POST');
this.respondJSON({salt: salt, B: 0});
// aborting if B=0
expect(this.requests).toEqual([]);
- expect(error).toHaveBeenCalled();
- expect(success).not.toHaveBeenCalled();
+ expect(srp.error).toHaveBeenCalledWith("Server send random number 0 - could not login.");
+ expect(srp.loggedIn).not.toHaveBeenCalled();
});
});