Skip to content

Commit bfa3b5c

Browse files
only persist secrets if we ever hydrated them in workspace webhook config handling (#19352)
1 parent 03b0d31 commit bfa3b5c

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

airbyte-server/src/main/java/io/airbyte/server/handlers/WorkspacesHandler.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,14 @@ public WorkspaceRead updateWorkspace(final WorkspaceUpdate workspacePatch) throw
186186

187187
LOGGER.debug("Patched Workspace before persisting: {}", workspace);
188188

189-
persistStandardWorkspace(workspace);
189+
if (workspacePatch.getWebhookConfigs() == null) {
190+
// We aren't persisting any secrets. It's safe (and necessary) to use the NoSecrets variant because
191+
// we never hydrated them in the first place.
192+
configRepository.writeStandardWorkspaceNoSecrets(workspace);
193+
} else {
194+
// We're saving new webhook configs, so we need to persist the secrets.
195+
persistStandardWorkspace(workspace);
196+
}
190197

191198
// after updating email or tracking info, we need to re-identify the instance.
192199
TrackingClientSingleton.get().identify(workspaceId);
@@ -204,7 +211,9 @@ public WorkspaceRead updateWorkspaceName(final WorkspaceUpdateName workspaceUpda
204211
.withName(workspaceUpdateName.getName())
205212
.withSlug(generateUniqueSlug(workspaceUpdateName.getName()));
206213

207-
persistStandardWorkspace(persistedWorkspace);
214+
// NOTE: it's safe (and necessary) to use the NoSecrets variant because we never hydrated them in
215+
// the first place.
216+
configRepository.writeStandardWorkspaceNoSecrets(persistedWorkspace);
208217

209218
return buildWorkspaceReadFromId(workspaceId);
210219
}

airbyte-server/src/test/java/io/airbyte/server/handlers/WorkspacesHandlerTest.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@
5858

5959
class WorkspacesHandlerTest {
6060

61-
public static final String FAILURE_NOTIFICATION_WEBHOOK = "http://airbyte.notifications/failure";
62-
public static final String NEW_WORKSPACE = "new workspace";
63-
public static final String TEST_NAME = "test-name";
61+
private static final String FAILURE_NOTIFICATION_WEBHOOK = "http://airbyte.notifications/failure";
62+
private static final String NEW_WORKSPACE = "new workspace";
63+
private static final String TEST_NAME = "test-name";
64+
65+
private static final String TEST_AUTH_TOKEN = "test-auth-token";
6466
private static final UUID WEBHOOK_CONFIG_ID = UUID.randomUUID();
6567
private static final JsonNode PERSISTED_WEBHOOK_CONFIGS = Jsons.deserialize(
6668
String.format("{\"webhookConfigs\": [{\"id\": \"%s\", \"name\": \"%s\", \"authToken\": {\"_secret\": \"a-secret_v1\"}}]}",
6769
WEBHOOK_CONFIG_ID, TEST_NAME));
70+
public static final String UPDATED = "updated";
6871
private ConfigRepository configRepository;
6972
private SecretsRepositoryWriter secretsRepositoryWriter;
7073
private ConnectionsHandler connectionsHandler;
@@ -149,7 +152,7 @@ void testCreateWorkspace() throws JsonValidationException, IOException, ConfigNo
149152
.securityUpdates(false)
150153
.notifications(List.of(generateApiNotification()))
151154
.defaultGeography(GEOGRAPHY_US)
152-
.webhookConfigs(List.of(new WebhookConfigWrite().name(TEST_NAME).authToken("test-auth-token")));
155+
.webhookConfigs(List.of(new WebhookConfigWrite().name(TEST_NAME).authToken(TEST_AUTH_TOKEN)));
153156

154157
final WorkspaceRead actualRead = workspacesHandler.createWorkspace(workspaceCreate);
155158
final WorkspaceRead expectedRead = new WorkspaceRead()
@@ -359,7 +362,7 @@ void testGetWorkspaceByConnectionId() {
359362
@Test
360363
void testUpdateWorkspace() throws JsonValidationException, ConfigNotFoundException, IOException {
361364
final io.airbyte.api.model.generated.Notification apiNotification = generateApiNotification();
362-
apiNotification.getSlackConfiguration().webhook("updated");
365+
apiNotification.getSlackConfiguration().webhook(UPDATED);
363366
final WorkspaceUpdate workspaceUpdate = new WorkspaceUpdate()
364367
.workspaceId(workspace.getWorkspaceId())
365368
.anonymousDataCollection(true)
@@ -372,7 +375,7 @@ void testUpdateWorkspace() throws JsonValidationException, ConfigNotFoundExcepti
372375
.webhookConfigs(List.of(new WebhookConfigWrite().name(TEST_NAME).authToken("test-auth-token")));
373376

374377
final Notification expectedNotification = generateNotification();
375-
expectedNotification.getSlackConfiguration().withWebhook("updated");
378+
expectedNotification.getSlackConfiguration().withWebhook(UPDATED);
376379
final StandardWorkspace expectedWorkspace = new StandardWorkspace()
377380
.withWorkspaceId(workspace.getWorkspaceId())
378381
.withCustomerId(workspace.getCustomerId())
@@ -398,7 +401,7 @@ void testUpdateWorkspace() throws JsonValidationException, ConfigNotFoundExcepti
398401
final WorkspaceRead actualWorkspaceRead = workspacesHandler.updateWorkspace(workspaceUpdate);
399402

400403
final io.airbyte.api.model.generated.Notification expectedNotificationRead = generateApiNotification();
401-
expectedNotificationRead.getSlackConfiguration().webhook("updated");
404+
expectedNotificationRead.getSlackConfiguration().webhook(UPDATED);
402405
final WorkspaceRead expectedWorkspaceRead = new WorkspaceRead()
403406
.workspaceId(workspace.getWorkspaceId())
404407
.customerId(workspace.getCustomerId())
@@ -419,6 +422,43 @@ void testUpdateWorkspace() throws JsonValidationException, ConfigNotFoundExcepti
419422
assertEquals(expectedWorkspaceRead, actualWorkspaceRead);
420423
}
421424

425+
@Test
426+
void testUpdateWorkspaceWithoutWebhookConfigs() throws JsonValidationException, ConfigNotFoundException, IOException {
427+
final io.airbyte.api.model.generated.Notification apiNotification = generateApiNotification();
428+
apiNotification.getSlackConfiguration().webhook(UPDATED);
429+
final WorkspaceUpdate workspaceUpdate = new WorkspaceUpdate()
430+
.workspaceId(workspace.getWorkspaceId())
431+
.anonymousDataCollection(false);
432+
433+
final Notification expectedNotification = generateNotification();
434+
expectedNotification.getSlackConfiguration().withWebhook(UPDATED);
435+
final StandardWorkspace expectedWorkspace = new StandardWorkspace()
436+
.withWorkspaceId(workspace.getWorkspaceId())
437+
.withCustomerId(workspace.getCustomerId())
438+
.withEmail(TEST_EMAIL)
439+
.withName(TEST_WORKSPACE_NAME)
440+
.withSlug(TEST_WORKSPACE_SLUG)
441+
.withAnonymousDataCollection(true)
442+
.withSecurityUpdates(false)
443+
.withNews(false)
444+
.withInitialSetupComplete(true)
445+
.withDisplaySetupWizard(false)
446+
.withTombstone(false)
447+
.withNotifications(List.of(expectedNotification))
448+
.withDefaultGeography(Geography.US)
449+
.withWebhookOperationConfigs(PERSISTED_WEBHOOK_CONFIGS);
450+
451+
when(uuidSupplier.get()).thenReturn(WEBHOOK_CONFIG_ID);
452+
453+
when(configRepository.getStandardWorkspaceNoSecrets(workspace.getWorkspaceId(), false))
454+
.thenReturn(expectedWorkspace)
455+
.thenReturn(expectedWorkspace.withAnonymousDataCollection(false));
456+
457+
workspacesHandler.updateWorkspace(workspaceUpdate);
458+
459+
verify(configRepository).writeStandardWorkspaceNoSecrets(expectedWorkspace);
460+
}
461+
422462
@Test
423463
@DisplayName("Updating workspace name should update name and slug")
424464
void testUpdateWorkspaceNoNameUpdate() throws JsonValidationException, ConfigNotFoundException, IOException {

0 commit comments

Comments
 (0)