This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
// https://docs.npmjs.com/cli/ping | ||
module.exports = function* () { | ||
this.status = 200; | ||
this.body = {}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
// https://docs.npmjs.com/cli/whoami | ||
module.exports = function* () { | ||
this.status = 200; | ||
this.body = { | ||
username: this.user.name, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict'; | ||
|
||
var should = require('should'); | ||
var request = require('supertest'); | ||
var mm = require('mm'); | ||
var app = require('../../../../servers/registry'); | ||
var config = require('../../../../config'); | ||
var tokenService = require('../../../../services/token'); | ||
var TestUtil = require('../../../utils'); | ||
|
||
describe('test/controllers/registry/user/ping.test.js', function () { | ||
afterEach(mm.restore); | ||
|
||
describe('/-/ping', function () { | ||
var token; | ||
|
||
beforeEach(function* () { | ||
mm(config, 'syncModel', 'all'); | ||
token = yield tokenService.createToken(TestUtil.admin); | ||
}); | ||
|
||
afterEach(function* () { | ||
yield tokenService.deleteToken(TestUtil.admin, token.token); | ||
}); | ||
|
||
describe('with write', function () { | ||
describe('has login', function () { | ||
it('should work', function (done) { | ||
request(app) | ||
.get('/-/ping?write=true') | ||
.set('authorization', 'Bearer ' + token.token) | ||
.expect(200, function (err) { | ||
should.not.exist(err); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('has not login', function () { | ||
it('should work', function (done) { | ||
request(app) | ||
.get('/-/ping?write=true') | ||
.set('authorization', 'Bearer mock_token') | ||
.expect(401, function (err) { | ||
should.not.exist(err); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with not write', function () { | ||
describe('has login', function () { | ||
it('should work', function (done) { | ||
request(app) | ||
.get('/-/ping') | ||
.set('authorization', 'Bearer ' + token.token) | ||
.expect(200, function (err) { | ||
should.not.exist(err); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('has not login', function () { | ||
it('should work', function (done) { | ||
request(app) | ||
.get('/-/ping') | ||
.set('authorization', 'Bearer ' + token.token) | ||
.expect(200, function (err) { | ||
should.not.exist(err); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
var should = require('should'); | ||
var request = require('supertest'); | ||
var mm = require('mm'); | ||
var app = require('../../../../servers/registry'); | ||
var config = require('../../../../config'); | ||
var tokenService = require('../../../../services/token'); | ||
var TestUtil = require('../../../utils'); | ||
|
||
describe('test/controllers/registry/user/whoami.test.js', function () { | ||
afterEach(mm.restore); | ||
|
||
describe('/-/whoami', function () { | ||
var token; | ||
|
||
beforeEach(function* () { | ||
mm(config, 'syncModel', 'all'); | ||
token = yield tokenService.createToken(TestUtil.admin); | ||
}); | ||
|
||
afterEach(function* () { | ||
yield tokenService.deleteToken(TestUtil.admin, token.token); | ||
}); | ||
|
||
it('should work', function (done) { | ||
request(app) | ||
.get('/-/whoami') | ||
.set('authorization', 'Bearer ' + token.token) | ||
.expect(200, function (err, res) { | ||
should.not.exist(err); | ||
res.body.username.should.eql(TestUtil.admin); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |