Skip to content

Commit

Permalink
CBG-3867 disallow creating a replication with an empty ID (#6844)
Browse files Browse the repository at this point in the history
  • Loading branch information
torcolvin authored May 28, 2024
1 parent 2d5a334 commit 84997a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions db/sg_replicate_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ func (m *sgReplicateManager) RefreshReplicationCfg(ctx context.Context) error {
if !exists {
replicator, initError := m.InitializeReplication(replicationCfg)
if initError != nil {
base.WarnfCtx(m.loggingCtx, "Error initializing replication %s: %v", initError)
base.WarnfCtx(m.loggingCtx, "Error initializing replication %s: %v", replicationID, initError)
continue
}
m.activeReplicators[replicationID] = replicator
Expand Down Expand Up @@ -1071,7 +1071,9 @@ func (m *sgReplicateManager) PutReplications(replications map[string]*Replicatio

// PUT _replication/replicationID
func (m *sgReplicateManager) UpsertReplication(ctx context.Context, replication *ReplicationUpsertConfig) (created bool, err error) {

if replication.ID == "" {
return false, base.HTTPErrorf(http.StatusBadRequest, "Replication ID is required")
}
created = true
addReplicationCallback := func(cluster *SGRCluster) (cancel bool, err error) {
_, exists := cluster.Replications[replication.ID]
Expand Down
9 changes: 9 additions & 0 deletions rest/replicatortest/replicator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8304,6 +8304,15 @@ func TestReplicatorWithCollectionsFailWithoutCollectionsEnabled(t *testing.T) {

}

func TestBanEmptyReplicationID(t *testing.T) {
rt := rest.NewRestTesterPersistentConfig(t)
defer rt.Close()

resp := rt.SendAdminRequest("POST", "/{{.db}}/_replication/", `{"remote": "fakeremote", "direction": "pull", "initial_state": "stopped"}`)
rest.RequireStatus(t, resp, http.StatusBadRequest)
require.Contains(t, string(resp.Body.Bytes()), "Replication ID is required")
}

func requireBodyEqual(t *testing.T, expected string, doc *db.Document) {
var expectedBody db.Body
require.NoError(t, base.JSONUnmarshal([]byte(expected), &expectedBody))
Expand Down

0 comments on commit 84997a0

Please sign in to comment.