4d239119a49ef97e11d6c9f8afb392276ad7d6d4
[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 stubLogger = require('../../stub-logger');
7 const lint = require('html-minifier-lint').lint; // eslint-disable-line node/no-unpublished-require
8
9 function lintHtml(html) {
10 const result = lint(html);
11 stubLogger.debug('validHtml', '', { result, html });
12 assert(!result);
13 }
14
15 describe('Template LoginHTML', function () {
16 let ctx, options;
17 beforeEach(function () {
18 ctx = {
19 clientProtocol: 'https',
20 };
21 options = {
22 authenticator: {
23 authnEnabled: ['indieAuth', 'DEBUG_ANY'],
24 secureAuthOnly: true,
25 },
26 manager: {
27 pageTitle: 'page',
28 },
29 dingus: {
30 selfBaseUrl: 'https://example.com/',
31 },
32 };
33 });
34
35 it('covers', function () {
36 const result = LoginHTML(ctx, options);
37 lintHtml(result);
38 assert(result);
39 });
40
41 it('renders errors and additional content', 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 lintHtml(result);
49 assert(result);
50 });
51
52 it('covers no indieAuth', function () {
53 options.authenticator.authnEnabled = [];
54 const result = LoginHTML(ctx, options);
55 lintHtml(result);
56 assert(result);
57 });
58
59 it('covers insecure not allowed', function () {
60 ctx.clientProtocol = undefined;
61 const result = LoginHTML(ctx, options);
62 lintHtml(result);
63 assert(result);
64 });
65
66 it('covers insecure allowed', function () {
67 ctx.clientProtocol = 'http';
68 options.authenticator.secureAuthOnly = false;
69 const result = LoginHTML(ctx, options);
70 lintHtml(result);
71 assert(result);
72 });
73
74 });