Skip to content

Commit

Permalink
fix: only save credentials when there are sensitive values (#3394)
Browse files Browse the repository at this point in the history
Closes: #3394
  • Loading branch information
ciyer committed Nov 15, 2024
1 parent 1bc8af1 commit d3d901d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,12 @@ export default function DataConnectorModalFooter({
useEffect(() => {
const dataConnectorId = createResult.data?.id;
if (dataConnectorId == null) return;
const shouldSaveCredentials = shouldSaveDataConnectorCredentials(
flatDataConnector.options,
cloudStorageState.saveCredentials,
validationResult?.isSuccess ?? false
);
if (!shouldSaveCredentials) return;

const options = flatDataConnector.options as CloudStorageDetailsOptions;
if (!schemata) return;
const sensitiveFieldNames = findSensitive(
schemata.find((s) => s.prefix === flatDataConnector.schema)
);
const options = flatDataConnector.options as CloudStorageDetailsOptions;
if (!options) return;
const dataConnectorSecretPatchList = sensitiveFieldNames
.map((name) => ({
name,
Expand All @@ -213,6 +207,13 @@ export default function DataConnectorModalFooter({
name: secret.name,
value: "" + secret.value,
}));
const shouldSaveCredentials = shouldSaveDataConnectorCredentials(
dataConnectorSecretPatchList,
cloudStorageState.saveCredentials,
validationResult?.isSuccess ?? false
);
if (!shouldSaveCredentials) return;

saveCredentials({
dataConnectorId,
dataConnectorSecretPatchList,
Expand Down Expand Up @@ -365,12 +366,12 @@ export default function DataConnectorModalFooter({
}

function shouldSaveDataConnectorCredentials(
flatDataConnectorOptions: CloudStorageDetailsOptions | undefined,
dataConnectorSecretPatchList: { name: string; value: string }[],
stateSaveCredentials: boolean,
validationSucceeded: boolean
) {
return !!(
flatDataConnectorOptions &&
dataConnectorSecretPatchList.length > 0 &&
stateSaveCredentials &&
validationSucceeded
);
Expand Down
44 changes: 44 additions & 0 deletions tests/cypress/e2e/groupV2DataConnectorCredentials.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,50 @@ describe("Set up data connectors with credentials", () => {
cy.wait("@listDataConnectors");
});

it("do not store credentials if there are none", () => {
fixtures
.listDataConnectors({ namespace: "test-2-group-v2" })
.testCloudStorage({ success: true })
.postDataConnector({ namespace: "test-2-group-v2" })
.dataConnectorSecrets({
fixture: "dataConnector/data-connector-secrets-empty.json",
})
.patchDataConnectorSecrets({
content: [],
// No call to postCloudStorageSecrets is expected
shouldNotBeCalled: true,
});
cy.visit("/v2/groups/test-2-group-v2");
cy.wait("@readGroupV2");
// add data connector
cy.getDataCy("add-data-connector").should("be.visible").click();
cy.wait("@getStorageSchema");

// Pick a provider
cy.getDataCy("data-storage-s3").click();
cy.getDataCy("data-provider-Switch").click();
cy.getDataCy("data-connector-edit-next-button").click();

// // Fill out the details
cy.get("#sourcePath").type("bucket/my-source");
cy.get("#endpoint").clear().type("https://s3-zh.os.switch.ch");
cy.getDataCy("test-data-connector-button").click();
cy.getDataCy("add-data-connector-continue-button")
.contains("Continue")
.click();
cy.getDataCy("data-connector-edit-mount").within(() => {
cy.get("#name").type("example storage without credentials");
});
cy.getDataCy("data-connector-edit-update-button").click();
cy.wait("@postDataConnector");
cy.getDataCy("data-connector-edit-body").should(
"contain.text",
"The data connector test-2-group-v2/example-storage-without-credentials has been successfully added."
);
cy.getDataCy("data-connector-edit-close-button").click();
cy.wait("@listDataConnectors");
});

it("resets validation state when content changes", () => {
fixtures
.getStorageSchema({ fixture: "cloudStorage/storage-schema-s3.json" })
Expand Down

0 comments on commit d3d901d

Please sign in to comment.