forked from github-tools/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.spec.js
More file actions
93 lines (76 loc) · 2.47 KB
/
auth.spec.js
File metadata and controls
93 lines (76 loc) · 2.47 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import expect from 'must';
import Github from '../lib/GitHub';
import testUser from './fixtures/user.js';
import {assertSuccessful, assertFailure} from './helpers/callbacks';
describe('Github', function() {
let github;
let user;
describe('with authentication', function() {
before(function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
auth: 'basic',
});
user = github.getUser();
});
// 200ms between tests so that Github has a chance to settle
beforeEach(function(done) {
setTimeout(done, 200);
});
it('should authenticate and return no errors', function(done) {
user.listNotifications(assertSuccessful(done));
});
});
describe('without authentication', function() {
before(function() {
github = new Github();
});
// 200ms between tests so that Github has a chance to settle
beforeEach(function(done) {
setTimeout(done, 200);
});
it('should read public information', function(done) {
let gist = github.getGist('f1c0f84e53aa6b98ec03');
gist.read(function(err, res, xhr) {
try {
expect(err).not.to.exist();
expect(res).to.exist();
expect(xhr).to.be.an.object();
done();
} catch (e) {
try {
if (err && err.response.headers['x-ratelimit-remaining'] === '0') {
done();
return;
}
} catch (e2) {
done(e);
}
done(e);
}
});
});
});
describe('with bad authentication', function() {
before(function() {
github = new Github({
username: testUser.USERNAME,
password: 'fake124',
auth: 'basic',
});
user = github.getUser();
});
// 200ms between tests so that Github has a chance to settle
beforeEach(function(done) {
setTimeout(done, 200);
});
it('should fail authentication and return err', function(done) {
user.listNotifications(assertFailure(done, function(err) {
expect(err.response.status).to.be.equal(401, 'Return 401 status for bad auth');
expect(err.response.data.message).to.equal('Bad credentials');
done();
}));
});
});
});