From 0c5369fd9299eb9bf7295e3925ce803c5473e2b8 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 22 Jun 2013 16:17:45 +0200 Subject: refactor: separate account from session --- spec/account_spec.js | 31 +++++++++++++++++++++++++++++++ spec/runner.html | 2 ++ spec/session_spec.js | 14 +++++++------- spec/signup_spec.js | 2 +- 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 spec/account_spec.js (limited to 'spec') diff --git a/spec/account_spec.js b/spec/account_spec.js new file mode 100644 index 0000000..4110778 --- /dev/null +++ b/spec/account_spec.js @@ -0,0 +1,31 @@ +describe("Account", function() { + describe("without seeded values", function(){ + beforeEach(function() { + account = new srp.Account(); + }); + + it("fetches the password from the password field", function(){ + expect(account.password()).toBe("password"); + }); + + it("fetches the login from the login field", function(){ + expect(account.login()).toBe("testuser"); + }); + + }); + + describe("with seeded values", function(){ + beforeEach(function() { + account = new srp.Account("login", "secret"); + }); + + it("uses the seeded password", function(){ + expect(account.password()).toBe("secret"); + }); + + it("uses the seeded login", function(){ + expect(account.login()).toBe("login"); + }); + + }); +}); diff --git a/spec/runner.html b/spec/runner.html index 3a458df..d0a5d5d 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -23,6 +23,7 @@ + @@ -30,6 +31,7 @@ + diff --git a/spec/session_spec.js b/spec/session_spec.js index 5802283..a1378a6 100644 --- a/spec/session_spec.js +++ b/spec/session_spec.js @@ -29,19 +29,19 @@ describe("Session", function() { var session; beforeEach(function() { - session = new srp.Session(compare.username, compare.password); + account = new srp.Account(compare.username, compare.password); + session = new srp.Session(account); }); - it("has the proper username", function() { - expect(session.getI()).toBe(compare.username); - }); - - it("calculates the proper M", function() { + it("calculates the proper M (INTEGRATION)", function() { session.calculateAndSetA(compare.a); session.calculations(compare.salt, compare.bb); expect(session.getS().toString(16)).toBe(compare.s); - // failing from here on... expect(session.key()).toBe(compare.k); expect(session.getM()).toBe(compare.m); }); + + it("delegates login", function() { + expect(session.login()).toBe(compare.username); + }); }); diff --git a/spec/signup_spec.js b/spec/signup_spec.js index 4f7a65d..48a62a7 100644 --- a/spec/signup_spec.js +++ b/spec/signup_spec.js @@ -11,7 +11,7 @@ describe("Signup with srp var", function() { specHelper.setupFakeXHR.apply(this); calculate = new srp.Calculate(); calculate.randomSalt = function() {return "4c78c3f8"}; - srp.session = new srp.Session(undefined, undefined, calculate); + srp.session = new srp.Session(undefined, calculate); }); afterEach(function() { -- cgit v1.2.3