summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-07-02 14:41:33 +0200
committerAzul <azul@leap.se>2012-07-02 14:41:33 +0200
commit516d5dc734155417e8e3beb8436e83ea101105b0 (patch)
tree7d1a0a4690e951f648198ce1974e1f960e5d713b
parent6bb45b271def50935bea8869ccb39c35c0c725be (diff)
parsing JSON responses tested and fixed
-rw-r--r--javascript/spec/login.js26
-rw-r--r--javascript/spec/signup.js15
-rw-r--r--javascript/spec/specHelper.js11
-rw-r--r--javascript/srp.js2
4 files changed, 50 insertions, 4 deletions
diff --git a/javascript/spec/login.js b/javascript/spec/login.js
index d73f9d7..13f5679 100644
--- a/javascript/spec/login.js
+++ b/javascript/spec/login.js
@@ -42,5 +42,31 @@ describe("Login", function() {
expect(window.location.hash).toBe("#logged_in")
});
+ it("logs in successfully with JSON (INTEGRATION)", function(){
+ var callback = sinon.spy();
+ var a = 'af141ae6';
+ var B = '887005895b1f5528b4e4dfdce914f73e763b96d3c901d2f41d8b8cd26255a75';
+ var salt = '5d3055e0acd3ddcfc15';
+ var M = 'be6d7db2186d5f6a2c55788479b6eaf75229a7ca0d9e7dc1f886f1970a0e8065'
+ var M2 = '2547cf26318519090f506ab73a68995a2626b1c948e6f603ef9e1b0b78bf0f7b';
+ srp = new SRP()
+ srp.success = callback;
+ var A = srp.calculateAndSetA(a);
+ srp.identify();
+
+ expect(this.requests.length).toBe(1);
+ expect(this.requests[0].url).toBe("handshake/");
+ expect(this.requests[0].requestBody).toBe("I=user&A=" + A);
+ specHelper.respondJSON(this.requests[0], {s: salt, B: B});
+ expect(this.requests.length).toBe(2);
+ expect(this.requests[1].url).toBe("authenticate/");
+ expect(this.requests[1].requestBody).toBe("M=" + M);
+ specHelper.respondJSON(this.requests[1], {M: M2});
+
+ expect(callback).toHaveBeenCalled();
+ expect(window.location.hash).toBe("#logged_in")
+ });
+
});
+
diff --git a/javascript/spec/signup.js b/javascript/spec/signup.js
index 8ead93b..90fe418 100644
--- a/javascript/spec/signup.js
+++ b/javascript/spec/signup.js
@@ -52,6 +52,21 @@ describe("Signup", function() {
expect(callback).toHaveBeenCalled();
});
+ it("identifies after successful registration with JSON (INTEGRATION)", function(){
+ var callback = sinon.spy();
+ this.srp.identify = callback;
+ this.srp.register();
+ expect(this.requests.length).toBe(1);
+ expect(this.requests[0].url).toBe("register/salt/");
+ expect(this.requests[0].requestBody).toBe("I=user");
+ specHelper.respondJSON(this.requests[0], {salt: "5d3055e0acd3ddcfc15"});
+ expect(this.requests.length).toBe(2);
+ expect(this.requests[1].url).toBe("register/user/");
+ expect(this.requests[1].requestBody).toBe("v=adcd57b4a4a05c2e205b0b7b30014d9ff635d8d8db2f502f08e9b9c132800c44");
+ specHelper.respondJSON(this.requests[1], {ok: true});
+ expect(callback).toHaveBeenCalled();
+ });
+
});
diff --git a/javascript/spec/specHelper.js b/javascript/spec/specHelper.js
index e923310..5f8071d 100644
--- a/javascript/spec/specHelper.js
+++ b/javascript/spec/specHelper.js
@@ -7,10 +7,15 @@ var specHelper = (function() {
body += content;
request.respond(200, header, body);
}
-
- var originalBigInteger = BigInteger;
-
+
+ function respondJSON(request, object) {
+ header = { "Content-Type": "application/json;charset=utf-8" };
+ body = JSON.stringify(object);
+ request.respond(200, header, body);
+ }
+
return {
+ respondJSON: respondJSON,
respondXML: respondXML
}
diff --git a/javascript/srp.js b/javascript/srp.js
index 7bb6e27..b84786e 100644
--- a/javascript/srp.js
+++ b/javascript/srp.js
@@ -140,7 +140,7 @@ function SRP()
function responseIsJSON() {
return (xhr.responseType == 'json') ||
- (xhr.responseHeaders["Content-Type"].indexOf('application/json') > 0)
+ (xhr.responseHeaders["Content-Type"].indexOf('application/json') >= 0)
}
function parseXML(xml) {