mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-23 22:27:34 -05:00
a7ba76423e
* test: add test for whoami * Update middleware.ts * test for user api * more test for user api * remove repeated code * refactor * Update index.spec.ts * add package test refactor others * chore: upgrade deps * chore: add test for package * chore: update test * update lock file * Update ci.yml * Update ci.yml * Update package.spec.ts * chore: update ci settings * chore: update deps * chore: update test
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import supertest from 'supertest';
|
|
|
|
import {initializeServer } from './_helper';
|
|
import { HTTP_STATUS } from '@verdaccio/commons-api';
|
|
import { HEADERS} from '@verdaccio/dev-commons';
|
|
import {$RequestExtend, $ResponseExtend} from "@verdaccio/dev-types";
|
|
|
|
const mockApiJWTmiddleware = jest.fn(() =>
|
|
(req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
|
req.remote_user = { name: 'foo', groups: [], real_groups: []}
|
|
_next();
|
|
}
|
|
);
|
|
|
|
jest.mock('@verdaccio/auth', () => ({
|
|
Auth: class {
|
|
apiJWTmiddleware() {
|
|
return mockApiJWTmiddleware();
|
|
}
|
|
allow_access (_d, f_, cb) {
|
|
cb(null, true)
|
|
}
|
|
}
|
|
}));
|
|
|
|
describe('whoami', () => {
|
|
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);
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
|
|
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');
|
|
});
|
|
});
|
|
});
|