This repository was archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgithub-auth-hook.test.js
More file actions
57 lines (49 loc) · 1.55 KB
/
Copy pathgithub-auth-hook.test.js
File metadata and controls
57 lines (49 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const { test } = require('ava');
const express = require('express');
const request = require('supertest');
let app;
let enableGitHubOAuth;
test.beforeEach(() => {
process.env.GITHUB_CLIENT_ID = '123';
process.env.GITHUB_CLIENT_SECRET = 'secret';
process.env.GITHUB_CALLBACK_URL = 'http://call.me.back';
app = express();
enableGitHubOAuth = require('./github-auth-hook');
enableGitHubOAuth(app);
});
test('should return 401 for the first call to /api/admin API', async t => {
t.plan(1);
return request(app)
.get(`/api/admin`)
.expect(401)
.expect(res => {
t.true(
res.body.message.indexOf(
'You have to identify yourself in order to use Unleash.'
) >= 0
);
});
});
test('should redirect to GH login page', async t => {
t.plan(3);
return request(app)
.get(`/api/admin/login`)
.expect(302)
.expect(res => {
t.true(res.header.location.indexOf('code') >= 0);
t.true(res.header.location.indexOf('scope=read') >= 0);
t.true(res.header.location.indexOf('client_id') >= 0);
});
});
test('should go back to callback', async t => {
t.plan(3);
return request(app)
.get(`/api/auth/callback`)
.expect(302)
.expect(res => {
t.true(res.header.location.indexOf('code') >= 0);
t.true(res.header.location.indexOf('scope=read') >= 0);
t.true(res.header.location.indexOf('client_id') >= 0);
});
});