support interaction between module and apps for updating templates before rendering
[squeep-authentication-module] / test / lib / template / login-html.js
1 /* eslint-env mocha */
2 'use strict';
3
4 const assert = require('assert');
5 const { LoginHTML } = require('../../../lib/template');
6 const lintHtml = require('../../lint-html');
7
8 describe('Template LoginHTML', function () {
9 let ctx, options;
10 beforeEach(function () {
11 ctx = {
12 clientProtocol: 'https',
13 };
14 options = {
15 authenticator: {
16 authnEnabled: ['indieAuth'],
17 secureAuthOnly: true,
18 },
19 manager: {
20 pageTitle: 'page',
21 },
22 dingus: {
23 selfBaseUrl: 'https://example.com/',
24 },
25 };
26 });
27
28 it('covers', async function () {
29 const result = LoginHTML(ctx, options);
30 await lintHtml(result);
31 assert(result);
32 });
33
34 it('covers local user', async function () {
35 options.authenticator.authnEnabled = ['argon2'];
36 const result = LoginHTML(ctx, options);
37 await lintHtml(result);
38 assert(result);
39 });
40
41 it('renders errors and additional content', async function () {
42 ctx.errors = ['an error', 'another error'];
43 options.manager.logoUrl = 'https://example.com/logo.png';
44 options.authenticator.loginBlurb = ['<p>This is a login page.</p>'];
45 options.authenticator.indieAuthBlurb = ['<p>Describe what IndieAuth allows one to do.</p>'];
46 options.authenticator.userBlurb = ['<p>Describe user login.</p>'];
47 const result = LoginHTML(ctx, options);
48 await lintHtml(result);
49 assert(result);
50 });
51
52 it('covers no indieAuth', async function () {
53 options.authenticator.authnEnabled = [];
54 const result = LoginHTML(ctx, options);
55 await lintHtml(result);
56 assert(result);
57 });
58
59 it('covers insecure not allowed', async function () {
60 ctx.clientProtocol = undefined;
61 const result = LoginHTML(ctx, options);
62 await lintHtml(result);
63 assert(result);
64 });
65
66 it('covers insecure allowed', async function () {
67 ctx.clientProtocol = 'http';
68 options.authenticator.secureAuthOnly = false;
69 const result = LoginHTML(ctx, options);
70 await lintHtml(result);
71 assert(result);
72 });
73
74 });