Skip to content

Commit

Permalink
PB-34289 WP3.3 - Edit password resource in v5 format
Browse files Browse the repository at this point in the history
  • Loading branch information
Benj1er committed Aug 9, 2024
1 parent 3d2d82a commit 7304bec
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ class EditResource extends Component {
const resource = this.props.context.resources.find(item => item.id === this.props.resourceId) || {};

return {
nameOriginal: resource.name || "",
name: resource.name || "",
nameOriginal: resource.metadata.name || "",
name: resource.metadata.name || "",
nameError: "",
nameWarning: "",
username: resource.username || "",
username: resource.metadata.username || "",
usernameError: "",
usernameWarning: "",
uri: resource.uri || "",
uri: resource.metadata.uris?.[0] || "",
uriError: "",
uriWarning: "",
passwordOriginal: null,
password: "",
passwordError: "",
passwordWarning: "",
description: resource.description || "",
description: resource.metadata.description || "",
descriptionError: "",
descriptionWarning: "",
totp: null, // The totp
Expand Down Expand Up @@ -468,9 +468,11 @@ class EditResource extends Component {
async updateResource() {
const resourceDto = {
id: this.props.resourceId,
name: this.state.name,
username: this.state.username,
uri: this.state.uri,
metadata: {
name: this.state.name,
username: this.state.username,
uris: [this.state.uri],
}
};

const isPasswordExpiryEnabled = this.props.passwordExpiryContext.isFeatureEnabled();
Expand Down Expand Up @@ -529,7 +531,7 @@ class EditResource extends Component {
* @deprecated will be removed when v2 support is dropped
*/
async updateResourceLegacy(resourceDto) {
resourceDto.description = this.state.description;
resourceDto.metadata.description = this.state.description;
const plaintextDto = this.hasSecretChanged() ? this.state.password : null;

return this.props.context.port.request("passbolt.resources.update", resourceDto, plaintextDto);
Expand All @@ -540,7 +542,9 @@ class EditResource extends Component {
* @param resourceDto
*/
async updateWithoutEncryptedDescription(resourceDto) {
resourceDto.description = this.state.description;
resourceDto.metadata.description = this.state.description;
resourceDto.metadata.resource_type_id = this.state.resourceTypeId;
// @TODO E2EE resource_type_id duplicate for resource
resourceDto.resource_type_id = this.state.resourceTypeId;
const plaintextDto = this.hasSecretChanged() ? this.state.password : null;

Expand All @@ -552,8 +556,10 @@ class EditResource extends Component {
* @param resourceDto
*/
async updateWithEncryptedDescription(resourceDto) {
resourceDto.metadata.resource_type_id = this.state.resourceTypeId;
// @TODO E2EE resource_type_id duplicate for resource
resourceDto.resource_type_id = this.state.resourceTypeId;
resourceDto.description = '';
resourceDto.metadata.description = '';
let plaintextDto = null;
if (this.hasSecretChanged()) {
plaintextDto = {
Expand All @@ -570,8 +576,10 @@ class EditResource extends Component {
* @param resourceDto
*/
async updateWithEncryptedDescriptionAndTotp(resourceDto) {
resourceDto.metadata.resource_type_id = this.state.resourceTypeId;
// @TODO E2EE resource_type_id duplicate for resource
resourceDto.resource_type_id = this.state.resourceTypeId;
resourceDto.description = '';
resourceDto.metadata.description = '';

let plaintextDto = null;
if (this.hasSecretChanged()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ describe("See the Edit Resource", () => {

it('Add totp when clicking on the add totp button.', async() => {
expect.assertions(4);
const context = defaultUserAppContext();
const props = defaultProps({context}); // The props to pass
const props = defaultProps(); // The props to pass
const secretDto = {password: "secret-decrypted", description: "description"};
mockContextRequest(props.context, () => secretDto);
const page = new EditResourcePage(props);
Expand All @@ -180,8 +179,9 @@ describe("See the Edit Resource", () => {

it('Edit totp when clicking on the edit totp button.', async() => {
expect.assertions(2);
const context = defaultUserAppContext({resources: [resourceWithTotpDto()]});
const props = defaultProps({context}); // The props to pass
const resource = resourceWithTotpDto();
const context = defaultUserAppContext({resources: [resource]});
const props = defaultProps({context, resourceId: resource.id}); // The props to pass
const secretDto = {
password: "secret-decrypted",
description: "description",
Expand All @@ -196,8 +196,9 @@ describe("See the Edit Resource", () => {
});

it('Delete totp when clicking on the delete totp button.', async() => {
const context = defaultUserAppContext({resources: [resourceWithTotpDto()]});
const props = defaultProps({context}); // The props to pass
const resource = resourceWithTotpDto();
const context = defaultUserAppContext({resources: [resource]});
const props = defaultProps({context, resourceId: resource.id}); // The props to pass
const secretDto = {
password: "secret-decrypted",
description: "description",
Expand Down Expand Up @@ -252,10 +253,13 @@ describe("See the Edit Resource", () => {

const onApiUpdateResourceMeta = {
id: resource.id,
name: resourceMeta.name,
uri: resourceMeta.uri,
username: resourceMeta.username,
description: "",
metadata: {
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION,
name: resourceMeta.name,
uris: [resourceMeta.uri],
username: resourceMeta.username,
description: "",
},
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION,
expired: date.toISO(),
};
Expand Down Expand Up @@ -291,10 +295,13 @@ describe("See the Edit Resource", () => {

const onApiUpdateResourceMeta = {
id: resource.id,
name: resourceMeta.name,
uri: resource.uri,
username: resource.username,
description: "",
metadata: {
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION,
name: resourceMeta.name,
uris: [resource.uri],
username: resource.username,
description: "",
},
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION
};

Expand Down Expand Up @@ -325,10 +332,13 @@ describe("See the Edit Resource", () => {

const onApiUpdateResourceMeta = {
id: resource.id,
name: resourceMeta.name,
uri: resource.uri,
username: resource.username,
description: resourceMeta.description,
metadata: {
name: resourceMeta.name,
uris: [resource.uri],
username: resource.username,
description: resourceMeta.description,
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_STRING
},
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_STRING
};

Expand Down Expand Up @@ -368,10 +378,13 @@ describe("See the Edit Resource", () => {

const onApiUpdateResourceMeta = {
id: resource.id,
name: resourceMeta.name,
uri: resource.uri,
username: resource.username,
description: "",
metadata: {
name: resourceMeta.name,
uris: [resource.uri],
username: resource.username,
description: "",
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP
},
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP
};

Expand Down Expand Up @@ -415,10 +428,13 @@ describe("See the Edit Resource", () => {

const onApiUpdateResourceDto = {
id: resource.id,
name: resourceMeta.name,
uri: resourceMeta.uri,
username: resourceMeta.username,
description: '',
metadata: {
name: resourceMeta.name,
uris: [resourceMeta.uri],
username: resourceMeta.username,
description: '',
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION
},
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION
};
const onApiUpdateSecretDto = {
Expand Down

0 comments on commit 7304bec

Please sign in to comment.