Changing AuthToken to be complex type so can have a version, rather than just a string

This commit is contained in:
simojenki
2021-02-25 13:55:45 +11:00
parent f295d3f015
commit c1e64dfc32
6 changed files with 17 additions and 11 deletions

View File

@@ -15,7 +15,7 @@ export class InMemoryMusicService implements MusicService {
password != undefined &&
this.users[username] == password
) {
return { authToken: "token123", userId: username, nickname: username };
return { authToken: { value: "token123", version: "1" }, userId: username, nickname: username };
} else {
return { message: `Invalid user:${username}` };
}

View File

@@ -18,7 +18,7 @@ describe("InMemoryLinkCodes", () => {
describe('when token is valid', () => {
it('should associate the token', () => {
const linkCode = linkCodes.mint();
const association = { authToken: "token123", nickname: "bob", userId: "1" };
const association = { authToken: { value: "token123", version: "22" }, nickname: "bob", userId: "1" };
linkCodes.associate(linkCode, association);
@@ -29,7 +29,7 @@ describe("InMemoryLinkCodes", () => {
describe('when token is valid', () => {
it('should throw an error', () => {
const invalidLinkCode = "invalidLinkCode";
const association = { authToken: "token123", nickname: "bob", userId: "1" };
const association = { authToken: { value: "token123", version: "33" }, nickname: "bob", userId: "1" };
expect(() => linkCodes.associate(invalidLinkCode, association)).toThrow(`Invalid linkCode ${invalidLinkCode}`)
});

View File

@@ -175,7 +175,7 @@ describe("api", () => {
describe("when there is a linkCode association", () => {
it("should return a device auth token", async () => {
const linkCode = linkCodes.mint();
const association = { authToken: "at", userId: "uid", nickname: "nn" };
const association = { authToken: { value: "at", version: "66" }, userId: "uid", nickname: "nn" };
linkCodes.associate(linkCode, association);
const ws = await createClientAsync(`${service.uri}?wsdl`, {
@@ -187,8 +187,8 @@ describe("api", () => {
expect(result[0]).toEqual({
getDeviceAuthTokenResult: {
authToken: association.authToken,
privateKey: "v1",
authToken: association.authToken.value,
privateKey: association.authToken.version,
userInfo: {
nickname: association.nickname,
userIdHashCode: crypto