Skip to content

Commit

Permalink
Mantain old change password call
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Candel authored and Ramon Candel committed Oct 1, 2024
1 parent e7586b7 commit b4a9d88
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
25 changes: 23 additions & 2 deletions src/drive/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HttpClient } from '../../shared/http/client';
import { UserSettings } from '../../shared/types/userSettings';
import {
ChangePasswordPayload,
ChangePasswordPayloadNew,
CheckChangeEmailExpirationResponse,
FriendInvite,
InitializeUserResponse,
Expand Down Expand Up @@ -95,12 +96,32 @@ export class Users {
}

/**
* Updates the authentication credentials and invalidates previous tokens
* Updates the authentication credentials and invalidates previous tokens (Legacy backend (drive-server))
* @param payload
*
* @returns {Promise<{token: string, newToken: string}>} A promise that returns new tokens for this user.
*/
public changePassword(payload: ChangePasswordPayload): Promise<{ token: string; newToken: string }> {
public changePasswordLegacy(payload: ChangePasswordPayload): Promise<{ token: string; newToken: string }> {
return this.client.patch(
'/user/password',
{
currentPassword: payload.currentEncryptedPassword,
newPassword: payload.newEncryptedPassword,
newSalt: payload.newEncryptedSalt,
mnemonic: payload.encryptedMnemonic,
privateKey: payload.encryptedPrivateKey,
},
this.headers(),
);
}

/**
* Updates the authentication credentials and invalidates previous tokens (New backend (drive-server-wip))
* @param payload
*
* @returns {Promise<{token: string, newToken: string}>} A promise that returns new tokens for this user.
*/
public changePassword(payload: ChangePasswordPayloadNew): Promise<{ token: string; newToken: string }> {
return this.client.patch(
'/users/password',
{
Expand Down
11 changes: 9 additions & 2 deletions src/drive/users/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export interface ChangePasswordPayload {
newEncryptedSalt: string;
encryptedMnemonic: string;
encryptedPrivateKey: string;
}

export interface ChangePasswordPayloadNew {
currentEncryptedPassword: string;
newEncryptedPassword: string;
newEncryptedSalt: string;
encryptedMnemonic: string;
encryptedPrivateKey: string;
encryptVersion: string;
}

Expand All @@ -27,7 +35,6 @@ export type FriendInvite = { guestEmail: string; host: number; accepted: boolean

export type UserPublicKeyResponse = { publicKey: string };


export type VerifyEmailChangeResponse = {
oldEmail: string;
newEmail: string;
Expand All @@ -38,4 +45,4 @@ export type VerifyEmailChangeResponse = {
};
};

export type CheckChangeEmailExpirationResponse = { isExpired: boolean };
export type CheckChangeEmailExpirationResponse = { isExpired: boolean };
10 changes: 5 additions & 5 deletions test/drive/users/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sinon from 'sinon';
import { Users } from '../../../src/drive';
import { headersWithToken } from '../../../src/shared/headers';
import { ChangePasswordPayload } from '../../../src/drive/users/types';
import { ChangePasswordPayloadNew } from '../../../src/drive/users/types';
import { ApiSecurity, AppDetails } from '../../../src/shared';
import { headersWithToken } from '../../../src/shared/headers';
import { HttpClient } from '../../../src/shared/http/client';

const httpClient = HttpClient.create('');
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('# users service tests', () => {
const email = '[email protected]';
const callStub = sinon.stub(httpClient, 'post').resolves({
publicKey: 'publicKey',
user: { uuid: 'exampleUuid', email }
user: { uuid: 'exampleUuid', email },
});

// Act
Expand All @@ -110,7 +110,7 @@ describe('# users service tests', () => {
expect(callStub.firstCall.args).toEqual(['/users/pre-create', { email }, headers]);
expect(body).toEqual({
publicKey: 'publicKey',
user: { uuid: 'exampleUuid', email }
user: { uuid: 'exampleUuid', email },
});
});
});
Expand All @@ -120,7 +120,7 @@ describe('# users service tests', () => {
// Arrange
const { client, headers } = clientAndHeaders();
const callStub = sinon.stub(httpClient, 'patch').resolves({});
const payload: ChangePasswordPayload = {
const payload: ChangePasswordPayloadNew = {
currentEncryptedPassword: '1',
encryptedMnemonic: '2',
encryptedPrivateKey: '3',
Expand Down

0 comments on commit b4a9d88

Please sign in to comment.