mirror of
https://github.com/Unleash/unleash.git
synced 2025-03-09 00:18:26 +01:00
fix: misunderstanding node URL api
This commit is contained in:
parent
69ded61448
commit
171b5182a5
@ -28,7 +28,7 @@ export default class ResetTokenService {
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
private readonly unleashBase: URL;
|
||||
private readonly unleashBase: string;
|
||||
|
||||
constructor(
|
||||
stores: IStores,
|
||||
@ -36,7 +36,7 @@ export default class ResetTokenService {
|
||||
) {
|
||||
this.store = stores.resetTokenStore;
|
||||
this.logger = getLogger('/services/reset-token-service.ts');
|
||||
this.unleashBase = new URL(server.unleashUrl);
|
||||
this.unleashBase = server.unleashUrl;
|
||||
}
|
||||
|
||||
async useAccessToken(token: IResetQuery): Promise<boolean> {
|
||||
@ -82,7 +82,7 @@ export default class ResetTokenService {
|
||||
}
|
||||
|
||||
private getExistingInvitationUrl(token: IResetToken) {
|
||||
return new URL(`/#/new-user?token=${token.token}`, this.unleashBase);
|
||||
return new URL(`${this.unleashBase}/new-user?token=${token.token}`);
|
||||
}
|
||||
|
||||
private async createResetUrl(
|
||||
@ -92,7 +92,7 @@ export default class ResetTokenService {
|
||||
): Promise<URL> {
|
||||
const token = await this.createToken(forUser, creator);
|
||||
return Promise.resolve(
|
||||
new URL(`${path}?token=${token.token}`, this.unleashBase),
|
||||
new URL(`${this.unleashBase}${path}?token=${token.token}`),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,28 @@ test.serial('Should create a reset link', async t => {
|
||||
);
|
||||
});
|
||||
|
||||
test.serial(
|
||||
'Should create a reset link with unleashUrl with context path',
|
||||
async t => {
|
||||
const localConfig = createTestConfig({
|
||||
server: { unleashUrl: 'http://localhost:4242/my/sub/path' },
|
||||
});
|
||||
const resetToken: ResetTokenService = new ResetTokenService(
|
||||
stores,
|
||||
localConfig,
|
||||
);
|
||||
|
||||
const url = await resetToken.createResetPasswordUrl(
|
||||
userIdToCreateResetFor,
|
||||
adminUser,
|
||||
);
|
||||
t.is(
|
||||
url.toString().substring(0, url.toString().indexOf('=')),
|
||||
`${localConfig.server.unleashUrl}/reset-password?token`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test.serial('Should create a welcome link', async t => {
|
||||
const url = await resetTokenService.createNewUserUrl(
|
||||
userIdToCreateResetFor,
|
||||
@ -108,8 +130,11 @@ test.serial('Creating a new token should expire older tokens', async t => {
|
||||
test.serial(
|
||||
'Retrieving valid invitation links should retrieve an object with userid key and token value',
|
||||
async t => {
|
||||
await resetTokenService.createToken(userIdToCreateResetFor, adminUser);
|
||||
|
||||
const token = await resetTokenService.createToken(
|
||||
userIdToCreateResetFor,
|
||||
adminUser,
|
||||
);
|
||||
t.truthy(token);
|
||||
const activeInvitations = await resetTokenService.getActiveInvitations();
|
||||
t.true(Object.keys(activeInvitations).length === 1);
|
||||
t.true(+Object.keys(activeInvitations)[0] === userIdToCreateResetFor);
|
||||
|
Loading…
Reference in New Issue
Block a user