Skip to content

Commit

Permalink
actor state get and save should return 400 if actor doesn't exist (da…
Browse files Browse the repository at this point in the history
…pr#1992)

* actor state get and save should return 404 if actor doesn't exist

* update ut

* 404 -> 400

Co-authored-by: LM <lemai>
Co-authored-by: Yaron Schneider <[email protected]>
  • Loading branch information
LMWF and yaron2 authored Sep 4, 2020
1 parent 4edaf3f commit c83e738
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pkg/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,18 @@ func (a *api) onGetActorState(reqCtx *fasthttp.RequestCtx) {
actorID := reqCtx.UserValue(actorIDParam).(string)
key := reqCtx.UserValue(stateKeyParam).(string)

hosted := a.actor.IsActorHosted(reqCtx, &actors.ActorHostedRequest{
ActorType: actorType,
ActorID: actorID,
})

if !hosted {
msg := NewErrorResponse("ERR_ACTOR_INSTANCE_MISSING", "")
respondWithError(reqCtx, 400, msg)
log.Debug(msg)
return
}

req := actors.GetStateRequest{
ActorType: actorType,
ActorID: actorID,
Expand Down
10 changes: 10 additions & 0 deletions pkg/http/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ func TestV1ActorEndpoints(t *testing.T) {
Data: fakeData,
}, nil)

mockActors.On("IsActorHosted", &actors.ActorHostedRequest{
ActorID: "fakeActorID",
ActorType: "fakeActorType",
}).Return(true)

testAPI.actor = mockActors

// act
Expand Down Expand Up @@ -516,6 +521,11 @@ func TestV1ActorEndpointsWithTracer(t *testing.T) {
Data: fakeData,
}, nil)

mockActors.On("IsActorHosted", &actors.ActorHostedRequest{
ActorID: "fakeActorID",
ActorType: "fakeActorType",
}).Return(true)

testAPI.actor = mockActors

// act
Expand Down
10 changes: 9 additions & 1 deletion tests/apps/actorfeatures/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func actorStateTest(testName string, w http.ResponseWriter, actorType string, id
}

// query a non-existing key. This should return 204 with 0 length response.
url = fmt.Sprintf(actorGetStateURLFormat, actorType, "999", "keynotpresent")
url = fmt.Sprintf(actorGetStateURLFormat, actorType, id, "keynotpresent")
body, err = httpCall("GET", url, nil, 204)
if err != nil {
log.Printf("actor state call failed: %s", err.Error())
Expand All @@ -392,6 +392,14 @@ func actorStateTest(testName string, w http.ResponseWriter, actorType string, id
return errors.New("expected 0 length reponse")
}

// query a non-existing actor. This should return 400.
url = fmt.Sprintf(actorGetStateURLFormat, actorType, "actoriddoesnotexist", "keynotpresent")
body, err = httpCall("GET", url, nil, 400)
if err != nil {
log.Printf("actor state call failed: %s", err.Error())
w.WriteHeader(http.StatusInternalServerError)
return err
}
} else if testName == "savestatetest2" {
// perform another transaction including a delete
url := fmt.Sprintf(actorSaveStateURLFormat, actorType, id)
Expand Down

0 comments on commit c83e738

Please sign in to comment.