Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PB-1380] [PB-1377] feat: add save and remove password endpoints #182

Merged
merged 8 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internxt/sdk",
"version": "1.4.59",
"version": "1.4.60",
apsantiso marked this conversation as resolved.
Show resolved Hide resolved
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
28 changes: 28 additions & 0 deletions src/drive/share/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,34 @@ export class Share {
...extraHeaders,
});
}

/**
* Add/edit sharing Password
* @param {string} sharingId - id of sharing.
* @param {string} code - code to encrypt password
* @param {string} password - plain password
apsantiso marked this conversation as resolved.
Show resolved Hide resolved
* @returns {Promise<SharingMeta>} A promise that returns the sharing info with the new encrypted password
*/
public saveSharingPassword(sharingId: string, code: string, password: string): Promise<SharingMeta> {
return this.client.post(
`sharings/${sharingId}/password`,
{
code,
password,
},
this.headers(),
);
}

/**
* Remove password protection from sharing
* @param {string} sharingId - id of sharing.
* @returns {Promise<void>} A promise that resolves when password was successfully deleted.
*/
public removeSharingPassword(sharingId: string): Promise<void> {
return this.client.delete(`sharings/${sharingId}/password`, this.headers());
}

/**
* Request access to shared folder.
*/
Expand Down
1 change: 1 addition & 0 deletions src/drive/share/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export type SharingMeta = {
sharedWith: string;
encryptionKey: string;
encryptedCode: string;
encryptedPassword: string | null;
encryptionAlgorithm: string;
createdAt: Date;
updatedAt: Date;
Expand Down
60 changes: 59 additions & 1 deletion test/drive/share/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import sinon from 'sinon';
import { GenerateShareLinkPayload, GetSharedDirectoryPayload } from '../../../src/drive/share/types';
import {
GenerateShareLinkPayload,
GetSharedDirectoryPayload,
SharedFiles,
SharingMeta,
} from '../../../src/drive/share/types';
import { Share } from '../../../src/drive';
import { basicHeaders, headersWithToken } from '../../../src/shared/headers';
import { ApiSecurity, AppDetails } from '../../../src/shared';
Expand Down Expand Up @@ -176,6 +181,59 @@ describe('# share service tests', () => {
});
});

describe('Add password to public sharing', () => {
it('Add password', async () => {
// Arrange
const mockUuid = '550e8400-e29b-41d4-a716-446655440000';
const sharedFile: SharingMeta = {
id: '1',
itemId: 'file123',
itemType: 'file',
ownerId: 'user123',
sharedWith: 'user456',
encryptionKey: 'sampleEncryptionKey',
encryptedCode: 'sampleEncryptedCode',
encryptedPassword: 'sampleEncryptedPassword',
encryptionAlgorithm: 'AES-256',
createdAt: new Date(),
updatedAt: new Date(),
type: 'private',
item: {} as SharedFiles,
itemToken: 'sampleItemToken',
};

const callStub = sinon.stub(httpClient, 'post').resolves(sharedFile);
const { client, headers } = clientAndHeaders();

// Act
const body = await client.saveSharingPassword(mockUuid, 'code', 'password');

// Assert
expect(callStub.firstCall.args).toMatchObject([
`sharings/${mockUuid}/password`,
{ code: 'code', password: 'password' },
headers,
]);
expect(body).toEqual(sharedFile);
});
});

describe('Remove password', () => {
it('Password removed', async () => {
// Arrange
const mockUuid = '550e8400-e29b-41d4-a716-446655440000';

const callStub = sinon.stub(httpClient, 'delete').resolves();
const { client, headers } = clientAndHeaders();

// Act
await client.removeSharingPassword(mockUuid);

// Assert
expect(callStub.firstCall.args).toMatchObject([`sharings/${mockUuid}/password`, headers]);
});
});

describe('get shares list', () => {
it('Should be called with right arguments & return content', async () => {
// Arrange
Expand Down
Loading