X-Git-Url: http://git.squeep.com/?p=squeep-indie-auther;a=blobdiff_plain;f=test%2Fsrc%2Ftemplate%2Fauthorization-request-html.js;fp=test%2Fsrc%2Ftemplate%2Fauthorization-request-html.js;h=b599df346cf9d7d6d61cd032172cf6d1c73f3dff;hp=0000000000000000000000000000000000000000;hb=b0103b0d496262c438b40bc20304081dbfe41e73;hpb=8ed81748bce7cea7904cac7225b20a60cafdfc16 diff --git a/test/src/template/authorization-request-html.js b/test/src/template/authorization-request-html.js new file mode 100644 index 0000000..b599df3 --- /dev/null +++ b/test/src/template/authorization-request-html.js @@ -0,0 +1,144 @@ +/* eslint-env mocha */ +'use strict'; + +const assert = require('assert'); +const template = require('../../../src/template/authorization-request-html'); +const Config = require('../../../config'); +const StubLogger = require('../../stub-logger'); +const lint = require('html-minifier-lint').lint; // eslint-disable-line node/no-unpublished-require + +const stubLogger = new StubLogger(); + +function lintHtml(html) { + const result = lint(html); + stubLogger.debug('validHtml', '', { result, html }); + assert(!result); +} + +describe('Authorization Request HTML Template', function () { + let ctx, config; + beforeEach(function () { + ctx = {}; + config = new Config('test'); + }); + it('renders', function () { + const result = template(ctx, config); + lintHtml(result); + assert(result); + }); + it('covers options', function () { + ctx.session = { + scope: ['profile', 'email'], + scopeIndex: { + 'profile': { + description: 'Profile', + }, + 'email': { + description: 'Email', + }, + 'create': { + description: 'Create', + profiles: ['https://exmaple.com/profile'], + }, + }, + me: new URL('https://example.com/profile'), + profiles: ['https://another.example.com/profile', 'https://example.com/profile'], + clientIdentifier: { + items: [{ + properties: { + url: 'https://client.example.com/app/', + summary: 'This is an app', + logo: 'https://client.example.com/app/logo.png', + name: 'Some Fancy Application', + }, + }], + }, + clientId: 'https://client.example.com/app/', + persist: 'encodedData', + redirectUri: 'https://client.example.com/app/_return', + }; + const result = template(ctx, config); + lintHtml(result); + assert(result); + }); + it('covers alternate scopes and client logo', function () { + ctx.session = { + scope: ['profile', 'email'], + scopeIndex: { + 'profile': { + description: 'Profile', + }, + 'email': { + description: 'Email', + }, + 'create': { + description: 'Create', + profiles: ['https://example.com/profile'], + }, + 'other': { + description: 'Another Scope', + profiles: ['https://example.com/profile'], + }, + }, + me: new URL('https://example.com/profile'), + profiles: ['https://another.example.com/profile', 'https://example.com/profile'], + clientIdentifier: { + items: [{ + properties: { + url: 'https://client.example.com/app/', + summary: 'This is an app', + logo: [{ + value: 'https://client.example.com/app/logo.png', + alt: 'alt', + }], + name: 'Some Fancy Application', + }, + }], + }, + clientId: 'https://client.example.com/app/', + persist: 'encodedData', + redirectUri: 'https://client.example.com/app/_return', + }; + const result = template(ctx, config); + lintHtml(result); + assert(result); + }); + it('covers partial data', function () { + ctx.session = { + scope: ['profile', 'email', 'create'], + profiles: ['https://another.example.com/profile', 'https://example.com/profile'], + clientIdentifier: { + items: [{ + properties: { + url: 'https://client.example.com/app/', + summary: 'This is an app', + logo: 'https://client.example.com/app/logo.png', + name: 'Some Fancy Application', + }, + }], + }, + clientId: 'https://client.example.com/app/', + persist: 'encodedData', + redirectUri: 'https://client.example.com/app/_return', + }; + const result = template(ctx, config); + lintHtml(result); + assert(result); + }); + it('covers partial data', function () { + ctx.session = { + scope: ['profile', 'email', 'create'], + profiles: [], + clientIdentifier: { + items: [{ + }], + }, + clientId: 'https://client.example.com/app/', + persist: 'encodedData', + redirectUri: 'https://client.example.com/app/_return', + }; + const result = template(ctx, config); + lintHtml(result); + assert(result); + }); +}); // Authorization Request HTML Template