Skip to content

Commit

Permalink
feat: ack expired err code (#1548)
Browse files Browse the repository at this point in the history
* feat: ack expired err code

* fix: test
  • Loading branch information
skynet2 authored Dec 18, 2023
1 parent c34234d commit aad1d14
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
34 changes: 34 additions & 0 deletions pkg/restapi/v1/oidc4ci/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,40 @@ func TestController_Ack(t *testing.T) {
err := controller.OidcAcknowledgement(echo.New().NewContext(req, rec))
assert.ErrorContains(t, err, "missing access token")
})

t.Run("ack expired", func(t *testing.T) {
mockOAuthProvider := NewMockOAuth2Provider(gomock.NewController(t))

ackMock := NewMockAckService(gomock.NewController(t))
mockOAuthProvider.EXPECT().NewAccessRequest(gomock.Any(), gomock.Any(), gomock.Any()).
Return(&fosite.AccessRequest{}, nil).AnyTimes()
controller := oidc4ci.NewController(&oidc4ci.Config{
OAuth2Provider: mockOAuthProvider,
AckService: ackMock,
Tracer: trace.NewNoopTracerProvider().Tracer(""),
})

ackMock.EXPECT().Ack(gomock.Any(), gomock.Any()).
Return(oidc4cisrv.ErrAckExpired)

req := httptest.NewRequest(http.MethodPost, "/", bytes.NewBuffer([]byte(`{
"credentials" : [{"ack_id" : "tx_id", "status" : "status", "error_description" : "err_txt"}]
}`)))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
req.Header.Set("Authorization", "Bearer xxxx")

rec := httptest.NewRecorder()

err := controller.OidcAcknowledgement(echo.New().NewContext(req, rec))
assert.NoError(t, err)
assert.Equal(t, http.StatusBadRequest, rec.Code)

var bd oidc4ci.AckErrorResponse
b, _ := io.ReadAll(rec.Body)

assert.NoError(t, json.Unmarshal(b, &bd))
assert.Equal(t, "expired_ack_id", bd.Error)
})
}

func TestController_OidcRegisterClient(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/service/oidc4ci/oidc4ci_acknowledgement.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type AckService struct {
cfg *AckServiceConfig
}

var ErrAckExpired = errors.New("expired_ack_id")

type AckServiceConfig struct {
AckStore ackStore
EventSvc eventService
Expand Down Expand Up @@ -89,7 +91,7 @@ func (s *AckService) HandleAckNotFound(
return err
}

return errors.New("ack expired")
return ErrAckExpired
}

// Ack acknowledges the interaction.
Expand Down
5 changes: 3 additions & 2 deletions pkg/service/oidc4ci/oidc4ci_acknowledgement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func TestAckFallback(t *testing.T) {
ErrorText: "some-random-text",
IssuerIdentifier: "https://someurl/some_issuer/v1.0",
})
assert.ErrorContains(t, err, "ack expired")
assert.ErrorIs(t, err, oidc4ci.ErrAckExpired)
assert.Equal(t, err.Error(), "expired_ack_id") // do not change this error code. wallet-sdk.
})

t.Run("success with short identifier", func(t *testing.T) {
Expand Down Expand Up @@ -157,7 +158,7 @@ func TestAckFallback(t *testing.T) {
ErrorText: "some-random-text",
IssuerIdentifier: "some_issuer/v1.0",
})
assert.ErrorContains(t, err, "ack expired")
assert.ErrorContains(t, err, "expired_ack_id")
})

t.Run("no store", func(t *testing.T) {
Expand Down

0 comments on commit aad1d14

Please sign in to comment.