Skip to content

Commit

Permalink
Manual pick: fix: prevent PUT operation from ingestion bot to update …
Browse files Browse the repository at this point in the history
…domain #13971
  • Loading branch information
pmbrull committed Nov 14, 2023
1 parent bd76fe0 commit 985f992
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,14 @@ private void updateDomain() {
return;
}

if (operation.isPut() && !nullOrEmpty(original.getDomain()) && updatedByBot()) {
// Revert change to non-empty domain if it is being updated by a bot
// This is to prevent bots from overwriting the domain. Domain need to be
// updated with a PATCH request
updated.setDomain(original.getDomain());
return;
}

EntityReference origDomain = original.getDomain();
EntityReference updatedDomain = updated.getDomain();
if ((operation.isPatch() || updatedDomain != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,38 @@ void test_domainInheritance(TestInfo test) throws HttpResponseException {
schemaTest.assertDomainInheritanceOverride(schema, createSchema.withDomain(null), SUB_DOMAIN.getEntityReference());
}

@Test
void test_domainUpdate(TestInfo test) throws HttpResponseException {
DatabaseService dbService = dbServiceTest.createEntity(dbServiceTest.createRequest(test), ADMIN_AUTH_HEADERS);
CreateDatabase createDb = dbTest.createRequest(test).withService(dbService.getFullyQualifiedName());
Database db = dbTest.createEntity(createDb, ADMIN_AUTH_HEADERS);
CreateDatabaseSchema createSchema = schemaTest.createRequest(test).withDatabase(db.getFullyQualifiedName());
DatabaseSchema schema = schemaTest.createEntity(createSchema, ADMIN_AUTH_HEADERS);
CreateTable createTable =
createRequest(test)
.withDatabaseSchema(schema.getFullyQualifiedName())
.withDomain(DOMAIN.getFullyQualifiedName());
Table table = createEntity(createTable, ADMIN_AUTH_HEADERS);

Table createdTable = getEntity(table.getId(), "domain", ADMIN_AUTH_HEADERS);
assertEquals(DOMAIN.getFullyQualifiedName(), createdTable.getDomain().getFullyQualifiedName());

// update table entity domain w/ PUT request w/ bot auth and check update is ignored
CreateTable updateTablePayload = createTable.withDomain(DOMAIN1.getFullyQualifiedName());
updateEntity(updateTablePayload, OK, INGESTION_BOT_AUTH_HEADERS);
Table updatedTable = getEntity(table.getId(), "domain", ADMIN_AUTH_HEADERS);
assertEquals(DOMAIN.getFullyQualifiedName(), updatedTable.getDomain().getFullyQualifiedName());

// patch domain w/ bot auth and check update is applied
patchEntity(
table.getId(),
JsonUtils.pojoToJson(createTable),
createdTable.withDomain(DOMAIN1.getEntityReference()),
INGESTION_BOT_AUTH_HEADERS);
Table patchedTable = getEntity(table.getId(), "domain", ADMIN_AUTH_HEADERS);
assertEquals(DOMAIN1.getFullyQualifiedName(), patchedTable.getDomain().getFullyQualifiedName());
}

@Test
void test_retentionPeriod(TestInfo test) throws HttpResponseException {
CreateDatabase createDatabase = dbTest.createRequest(getEntityName(test)).withRetentionPeriod("P30D");
Expand Down

0 comments on commit 985f992

Please sign in to comment.