Skip to content

Commit

Permalink
do not call save credentials if the validation failed
Browse files Browse the repository at this point in the history
  • Loading branch information
ciyer committed Aug 27, 2024
1 parent 756da48 commit 65dd221
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ export default function CloudStorageModal({
const shouldSaveCredentials = !!(
isV2 &&
storageDetails.options &&
state.saveCredentials
state.saveCredentials &&
validationSucceeded
);
if (!shouldSaveCredentials) {
return;
Expand Down Expand Up @@ -423,6 +424,7 @@ export default function CloudStorageModal({
schema,
storageDetails.options,
storageDetails.schema,
validationSucceeded,
]);

// Visual elements
Expand Down
7 changes: 6 additions & 1 deletion tests/cypress/e2e/projectV2DataSourceCredentials.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ describe("Set up data sources with credentials", () => {
fixture: "cloudStorage/cloud-storage-with-secrets-values-empty.json",
name: "getCloudStorageV2",
})
.testCloudStorage({ success: false });
.testCloudStorage({ success: false })
.postCloudStorageSecrets({
content: [],
// No call to postCloudStorageSecrets is expected
shouldNotBeCalled: true,
});
cy.visit("/v2/projects/user1-uuid/test-2-v2-project");
cy.wait("@readProjectV2");
// add data source
Expand Down
4 changes: 4 additions & 0 deletions tests/cypress/support/renkulab-fixtures/cloudStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface PostCloudStorageSecretsArgs extends CloudStorageSecretsArgs {
name: string;
value: string;
}[];
shouldNotBeCalled?: boolean;
}

interface TestCloudStorageArgs extends SimpleFixture {
Expand Down Expand Up @@ -112,6 +113,7 @@ export function CloudStorage<T extends FixturesConstructor>(Parent: T) {
content,
fixture = "cloudStorage/cloud-storage-secrets.json",
name = "postCloudStorageSecrets",
shouldNotBeCalled = false,
storageId = 2,
} = args ?? {};
cy.fixture(fixture).then((secrets) => {
Expand All @@ -120,6 +122,8 @@ export function CloudStorage<T extends FixturesConstructor>(Parent: T) {
"POST",
`/ui-server/api/data/storages_v2/${storageId}/secrets`,
(req) => {
if (shouldNotBeCalled)
throw new Error("No call to post secrets expected");
const newSecrets = req.body;
expect(newSecrets.length).equal(content.length);
newSecrets.forEach((secret, index) => {
Expand Down

0 comments on commit 65dd221

Please sign in to comment.