X-Git-Url: http://git.squeep.com/?p=squeep-authentication-module;a=blobdiff_plain;f=test%2Flib%2Fsession-manager.js;h=bf8df03b94f8875bfa5306e6f9a59f51546cfbe6;hp=daff0501e3f0cab2cd8a00a414cf01c4a30ab303;hb=a44a8c411be1831e7b2418212ee0b295206ca27a;hpb=afa866e6bb4d5af652379295c9497c2caf4ecc92 diff --git a/test/lib/session-manager.js b/test/lib/session-manager.js index daff050..bf8df03 100644 --- a/test/lib/session-manager.js +++ b/test/lib/session-manager.js @@ -84,7 +84,9 @@ describe('SessionManager', function () { it('covers valid profile', async function () { ctx.parsedBody.me = 'https://example.com/profile'; manager.indieAuthCommunication.fetchProfile.resolves({ - authorizationEndpoint: 'https://example.com/auth', + metadata: { + authorizationEndpoint: 'https://example.com/auth', + }, }); await manager.postAdminLogin(res, ctx); assert.strictEqual(res.statusCode, 302); @@ -104,11 +106,48 @@ describe('SessionManager', function () { it('covers invalid profile response endpoint', async function () { ctx.parsedBody.me = 'https://example.com/profile'; manager.indieAuthCommunication.fetchProfile.resolves({ - authorizationEndpoint: 'not an auth endpoint', + metadata: { + authorizationEndpoint: 'not an auth endpoint', + }, }); await manager.postAdminLogin(res, ctx); assert(!res.setHeader.called); }); + describe('living-standard-20220212', function () { + it('covers valid profile', async function () { + ctx.parsedBody.me = 'https://example.com/profile'; + manager.indieAuthCommunication.fetchProfile.resolves({ + metadata: { + issuer: 'https://example.com/', + authorizationEndpoint: 'https://example.com/auth', + }, + }); + await manager.postAdminLogin(res, ctx); + assert.strictEqual(res.statusCode, 302); + }); + it('covers bad issuer url', async function () { + ctx.parsedBody.me = 'https://example.com/profile'; + manager.indieAuthCommunication.fetchProfile.resolves({ + metadata: { + issuer: 'http://example.com/?bah#foo', + authorizationEndpoint: 'https://example.com/auth', + }, + }); + await manager.postAdminLogin(res, ctx); + assert(!res.setHeader.called); + }); + it('covers unparsable issuer url', async function () { + ctx.parsedBody.me = 'https://example.com/profile'; + manager.indieAuthCommunication.fetchProfile.resolves({ + metadata: { + issuer: 'not a url', + authorizationEndpoint: 'https://example.com/auth', + }, + }); + await manager.postAdminLogin(res, ctx); + assert(!res.setHeader.called); + }); + }); // living-standard-20220212 }); // postAdminLogin describe('getAdminLogout', function () { @@ -128,7 +167,9 @@ describe('SessionManager', function () { me, }); manager.indieAuthCommunication.fetchProfile.resolves({ - authorizationEndpoint, + metadata: { + authorizationEndpoint, + }, }); sinon.stub(manager.mysteryBox, 'unpack').resolves({ authorizationEndpoint, @@ -242,13 +283,48 @@ describe('SessionManager', function () { }); manager.indieAuthCommunication.fetchProfile.restore(); sinon.stub(manager.indieAuthCommunication, 'fetchProfile').resolves({ - authorizationEndpoint: 'https://elsewhere.example.com/auth', + metadata: { + authorizationEndpoint: 'https://elsewhere.example.com/auth', + }, }); await manager.getAdminIA(res, ctx); assert(ctx.errors.length); }); + describe('living-standard-20220212', function () { + beforeEach(function () { + manager.indieAuthCommunication.fetchProfile.resolves({ + metadata: { + authorizationEndpoint, + issuer: 'https://example.com/', + }, + }); + manager.mysteryBox.unpack.resolves({ + authorizationEndpoint, + issuer: 'https://example.com/', + state, + me, + }); + }); + it('covers valid', async function () { + ctx.queryParams['state'] = state; + ctx.queryParams['code'] = 'codeCodeCode'; + ctx.queryParams['iss'] = 'https://example.com/'; + + await manager.getAdminIA(res, ctx); + + assert.strictEqual(res.statusCode, 302); + }); + it('covers mis-matched issuer', async function () { + ctx.queryParams['state'] = state; + ctx.queryParams['code'] = 'codeCodeCode'; + + await manager.getAdminIA(res, ctx); + + assert(ctx.errors.length); + }); + }); // living-standard-20220212 }); // getAdminIA }); // SessionManager \ No newline at end of file