Skip to content

Commit f67ba93

Browse files
committed
Add validation to reject updates to deprecated domains
UpdateDomain now returns an error when attempting to update a domain with DEPRECATED status, preventing unintended modifications to deprecated domains. Changes: - Add errDomainDeprecated error constant - Check domain status before applying updates - Add test case to verify deprecated domain updates are rejected Signed-off-by: Diana Zawadzki <[email protected]>
1 parent 1ec9f3b commit f67ba93

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

common/domain/errors.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var (
3434
errInvalidGracefulFailover = &types.BadRequestError{Message: "Cannot start graceful failover without updating active cluster or in local domain."}
3535
errActiveClusterNameRequired = &types.BadRequestError{Message: "ActiveClusterName is required for all global domains."}
3636
errLocalDomainsCannotFailover = &types.BadRequestError{Message: "Local domains cannot perform failovers or change replication configuration"}
37-
38-
errInvalidRetentionPeriod = &types.BadRequestError{Message: "A valid retention period is not set on request."}
39-
errInvalidArchivalConfig = &types.BadRequestError{Message: "Invalid to enable archival without specifying a uri."}
37+
errDomainDeprecated = &types.BadRequestError{Message: "Domain is deprecated."}
38+
errInvalidRetentionPeriod = &types.BadRequestError{Message: "A valid retention period is not set on request."}
39+
errInvalidArchivalConfig = &types.BadRequestError{Message: "Invalid to enable archival without specifying a uri."}
4040
)

common/domain/handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ func (d *handlerImpl) UpdateDomain(
426426
if err != nil {
427427
return nil, err
428428
}
429+
// Check if domain is deprecated
430+
if currentDomainState.Info != nil && currentDomainState.Info.Status == persistence.DomainStatusDeprecated {
431+
return nil, errDomainDeprecated
432+
}
429433

430434
// todo (david.porter) remove this and push the deepcopy into each of the branches
431435
getResponse := currentDomainState.DeepCopy()

common/domain/handler_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,43 @@ func TestHandler_UpdateDomain(t *testing.T) {
28512851
},
28522852
err: errors.New("handle-transmission-task-error"),
28532853
},
2854+
{
2855+
name: "Error case - update deprecated domain should return errDomainDeprecated",
2856+
setupMock: func(domainManager *persistence.MockDomainManager, updateRequest *types.UpdateDomainRequest, archivalMetadata *archiver.MockArchivalMetadata, timeSource clock.MockedTimeSource, _ *MockReplicator) {
2857+
domainResponse := &persistence.GetDomainResponse{
2858+
ReplicationConfig: &persistence.DomainReplicationConfig{
2859+
ActiveClusterName: cluster.TestCurrentClusterName,
2860+
Clusters: []*persistence.ClusterReplicationConfig{
2861+
{ClusterName: cluster.TestCurrentClusterName}, {ClusterName: cluster.TestAlternativeClusterName}},
2862+
},
2863+
Config: &persistence.DomainConfig{
2864+
Retention: 1,
2865+
EmitMetric: true,
2866+
HistoryArchivalStatus: types.ArchivalStatusDisabled,
2867+
VisibilityArchivalStatus: types.ArchivalStatusDisabled,
2868+
BadBinaries: types.BadBinaries{Binaries: map[string]*types.BadBinaryInfo{}},
2869+
IsolationGroups: types.IsolationGroupConfiguration{},
2870+
AsyncWorkflowConfig: types.AsyncWorkflowConfiguration{Enabled: true},
2871+
},
2872+
Info: &persistence.DomainInfo{
2873+
Name: constants.TestDomainName,
2874+
ID: constants.TestDomainID,
2875+
Status: persistence.DomainStatusDeprecated,
2876+
},
2877+
IsGlobalDomain: true,
2878+
LastUpdatedTime: timeSource.Now().UnixNano(),
2879+
FailoverVersion: cluster.TestCurrentClusterInitialFailoverVersion,
2880+
}
2881+
domainManager.EXPECT().GetMetadata(ctx).Return(&persistence.GetMetadataResponse{}, nil).Times(1)
2882+
domainManager.EXPECT().GetDomain(ctx, &persistence.GetDomainRequest{Name: updateRequest.GetName()}).
2883+
Return(domainResponse, nil).Times(1)
2884+
},
2885+
request: &types.UpdateDomainRequest{
2886+
Name: constants.TestDomainName,
2887+
ActiveClusterName: common.Ptr(cluster.TestAlternativeClusterName),
2888+
},
2889+
err: errDomainDeprecated,
2890+
},
28542891
}
28552892

28562893
for _, tc := range testCases {

0 commit comments

Comments
 (0)