2020-06-30 14:55:14 -05:00
|
|
|
import supertest from 'supertest';
|
|
|
|
|
|
|
|
import { HTTP_STATUS } from '@verdaccio/commons-api';
|
2020-08-13 16:27:00 -05:00
|
|
|
import { HEADERS } from '@verdaccio/dev-commons';
|
|
|
|
import { $RequestExtend, $ResponseExtend } from '@verdaccio/dev-types';
|
|
|
|
import { initializeServer } from './_helper';
|
2020-06-30 14:55:14 -05:00
|
|
|
|
2020-08-13 16:27:00 -05:00
|
|
|
const mockApiJWTmiddleware = jest.fn(() => (req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
|
|
|
req.remote_user = { name: 'foo', groups: [], real_groups: [] };
|
|
|
|
_next();
|
|
|
|
});
|
2020-06-30 14:55:14 -05:00
|
|
|
|
|
|
|
jest.mock('@verdaccio/auth', () => ({
|
2020-08-13 16:27:00 -05:00
|
|
|
Auth: class {
|
|
|
|
apiJWTmiddleware() {
|
|
|
|
return mockApiJWTmiddleware();
|
|
|
|
}
|
|
|
|
allow_access(_d, f_, cb) {
|
|
|
|
cb(null, true);
|
|
|
|
}
|
|
|
|
},
|
2020-06-30 14:55:14 -05:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('whoami', () => {
|
2020-08-13 16:27:00 -05:00
|
|
|
test.skip('should test referer /whoami endpoint', async (done) => {
|
|
|
|
return supertest(await initializeServer('whoami.yaml'))
|
|
|
|
.get('/whoami')
|
|
|
|
.set('referer', 'whoami')
|
|
|
|
.expect(HTTP_STATUS.OK)
|
|
|
|
.end(done);
|
|
|
|
});
|
2020-06-30 14:55:14 -05:00
|
|
|
|
2020-08-13 16:27:00 -05:00
|
|
|
test.skip('should test no referer /whoami endpoint', async (done) => {
|
|
|
|
return supertest(await initializeServer('whoami.yaml'))
|
|
|
|
.get('/whoami')
|
|
|
|
.expect(HTTP_STATUS.NOT_FOUND)
|
|
|
|
.end(done);
|
|
|
|
});
|
2020-06-30 14:55:14 -05:00
|
|
|
|
2020-08-13 16:27:00 -05:00
|
|
|
test('should return the logged username', async () => {
|
|
|
|
return supertest(await initializeServer('whoami.yaml'))
|
|
|
|
.get('/-/whoami')
|
|
|
|
.set('Accept', HEADERS.JSON)
|
|
|
|
.expect('Content-Type', HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HTTP_STATUS.OK)
|
|
|
|
.then((response) => {
|
|
|
|
expect(response.body.username).toEqual('foo');
|
|
|
|
});
|
|
|
|
});
|
2020-06-30 14:55:14 -05:00
|
|
|
});
|