Skip to content

Commit

Permalink
[scd] check subscription version is present and correct when deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick committed Jan 25, 2024
1 parent 9505bb0 commit 19b6817
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/dev/probe_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if ! docker run --link "$OAUTH_CONTAINER":oauth \
--network dss_sandbox-default \
-v "${RESULTFILE}:/app/test_result" \
-w /app/monitoring/prober \
interuss/monitoring:v0.2.0 \
interuss/monitoring:v0.3.0 \
pytest \
"${1:-.}" \
-rsx \
Expand Down
11 changes: 11 additions & 0 deletions pkg/scd/subscriptions_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,13 @@ func (a *Server) DeleteSubscription(ctx context.Context, req *restapi.DeleteSubs
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}

// Retrieve Subscription Version
version := scdmodels.OVN(req.Version)
if version == "" {
return restapi.DeleteSubscriptionResponseSet{Response400: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Missing version"))}}
}

// Retrieve ID of client making call
if req.Auth.ClientID == nil {
return restapi.DeleteSubscriptionResponseSet{Response403: &restapi.ErrorResponse{
Expand All @@ -493,6 +500,8 @@ func (a *Server) DeleteSubscription(ctx context.Context, req *restapi.DeleteSubs
return stacktrace.Propagate(
stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Subscription is owned by different client"),
"Subscription owned by %s, but %s attempted to delete", old.Manager, *req.Auth.ClientID)
case old.Version != version:
return stacktrace.NewErrorWithCode(dsserr.VersionMismatch, "Subscription version %s is not current", version)
}

// Get dependent Operations
Expand Down Expand Up @@ -537,6 +546,8 @@ func (a *Server) DeleteSubscription(ctx context.Context, req *restapi.DeleteSubs
return restapi.DeleteSubscriptionResponseSet{Response400: errResp}
case dsserr.NotFound:
return restapi.DeleteSubscriptionResponseSet{Response404: errResp}
case dsserr.VersionMismatch:
return restapi.DeleteSubscriptionResponseSet{Response409: errResp}
default:
return restapi.DeleteSubscriptionResponseSet{Response500: &api.InternalServerErrorBody{
ErrorMessage: *dsserr.Handle(ctx, stacktrace.Propagate(err, "Got an unexpected error"))}}
Expand Down
2 changes: 1 addition & 1 deletion test/migrations/rid_db_post_migration_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ docker run --link dummy-oauth-for-testing:oauth \
--link core-service-for-testing:core-service \
-v "${RESULTFILE}:/app/test_result" \
-w /app/monitoring/prober \
interuss/monitoring:v0.2.0 \
interuss/monitoring:v0.3.0 \
pytest \
"${1:-.}" \
-rsx \
Expand Down

0 comments on commit 19b6817

Please sign in to comment.