authelia/test/unitary/user_data_store/totp_secret.test.ts

73 lines
1.8 KiB
TypeScript
Raw Normal View History

2017-05-16 21:17:46 +00:00
import * as assert from "assert";
import * as Promise from "bluebird";
import * as sinon from "sinon";
import * as MockDate from "mockdate";
import UserDataStore from "../../../src/lib/UserDataStore";
describe("test user data store", function() {
describe("test totp secrets store", test_totp_secrets);
});
function test_totp_secrets() {
it("should save and reload a totp secret", function() {
const options = {
inMemoryOnly: true
};
const data_store = new UserDataStore(options);
const userid = "user";
const secret = {
ascii: "abc",
base32: "ABCDKZLEFZGREJK",
otpauth_url: "totp://test"
};
return data_store.set_totp_secret(userid, secret)
.then(function() {
return data_store.get_totp_secret(userid);
})
.then(function(doc) {
assert("_id" in doc);
assert.equal(doc.userid, "user");
assert.equal(doc.secret.ascii, "abc");
assert.equal(doc.secret.base32, "ABCDKZLEFZGREJK");
return Promise.resolve();
});
});
it("should only remember last secret", function() {
const options = {
inMemoryOnly: true
};
const data_store = new UserDataStore(options);
const userid = "user";
const secret1 = {
ascii: "abc",
base32: "ABCDKZLEFZGREJK",
otpauth_url: "totp://test"
};
const secret2 = {
ascii: "def",
base32: "XYZABC",
otpauth_url: "totp://test"
};
return data_store.set_totp_secret(userid, secret1)
.then(function() {
return data_store.set_totp_secret(userid, secret2);
})
.then(function() {
return data_store.get_totp_secret(userid);
})
.then(function(doc) {
assert("_id" in doc);
assert.equal(doc.userid, "user");
assert.equal(doc.secret.ascii, "def");
assert.equal(doc.secret.base32, "XYZABC");
return Promise.resolve();
});
});
}