Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into issue-615-verification-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
andresuribe87 authored Aug 3, 2023
2 parents 2b37494 + d0f76fc commit 740a33a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 42 deletions.
8 changes: 4 additions & 4 deletions pkg/server/pagination/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const (
PageTokenParam = "pageToken"
)

// ParsePaginationParams reads the PageSizeParam and PageTokenParam from the URL parameters and populates the passed in
// ParsePaginationQueryValues reads the PageSizeParam and PageTokenParam from the URL parameters and populates the passed in
// pageRequest. The value encoded in PageTokenParam is assumed to be the base64url encoding of a PageToken. It is an
// error for the query params to be different from the query params encoded in the PageToken. Any error during the
// execution is responded to using the passed in gin.Context. The return value corresponds to whether there was an
// error within the function.
func ParsePaginationParams(c *gin.Context, pageRequest *PageRequest) bool {
pageSizeStr := framework.GetParam(c, PageSizeParam)
func ParsePaginationQueryValues(c *gin.Context, pageRequest *PageRequest) bool {
pageSizeStr := framework.GetQueryValue(c, PageSizeParam)

if pageSizeStr != nil {
pageSize, err := strconv.Atoi(*pageSizeStr)
Expand All @@ -48,7 +48,7 @@ func ParsePaginationParams(c *gin.Context, pageRequest *PageRequest) bool {
pageRequest.PageSize = &pageSize
}

queryPageToken := framework.GetParam(c, PageTokenParam)
queryPageToken := framework.GetQueryValue(c, PageTokenParam)
if queryPageToken != nil {
errMsg := "token value cannot be decoded"
tokenData, err := base64.RawURLEncoding.DecodeString(*queryPageToken)
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/router/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (dr DIDRouter) ListDIDsByMethod(c *gin.Context) {
Deleted: getIsDeleted,
}
var pageRequest pagination.PageRequest
if pagination.ParsePaginationParams(c, &pageRequest) {
if pagination.ParsePaginationQueryValues(c, &pageRequest) {
return
}
getDIDsRequest.PageRequest = pageRequest.ToServicePage()
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/router/presentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (pr PresentationRouter) ListSubmissions(c *gin.Context) {
}

var pageRequest pagination.PageRequest
if pagination.ParsePaginationParams(c, &pageRequest) {
if pagination.ParsePaginationQueryValues(c, &pageRequest) {
return
}

Expand Down
13 changes: 5 additions & 8 deletions pkg/server/server_did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,11 @@ func TestDIDAPI(t *testing.T) {

w := httptest.NewRecorder()
badParams := url.Values{
"method": []string{"key"},
"pageSize": []string{"1"},
"pageToken": []string{"made up token"},
}
req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key?"+badParams.Encode(), nil)
c := newRequestContextWithURLValues(w, req, badParams)
c := newRequestContextWithParams(w, req, map[string]string{"method": "key"})
didService.ListDIDsByMethod(c)
assert.Contains(tt, w.Body.String(), "token value cannot be decoded")
})
Expand All @@ -536,11 +535,10 @@ func TestDIDAPI(t *testing.T) {

w := httptest.NewRecorder()
params := url.Values{
"method": []string{"key"},
"pageSize": []string{"1"},
}
req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key?"+params.Encode(), nil)
c := newRequestContextWithURLValues(w, req, params)
c := newRequestContextWithParams(w, req, map[string]string{"method": "key"})

didRouter.ListDIDsByMethod(c)

Expand All @@ -553,7 +551,7 @@ func TestDIDAPI(t *testing.T) {
w = httptest.NewRecorder()
params["pageToken"] = []string{listDIDsByMethodResponse.NextPageToken}
req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key?"+params.Encode(), nil)
c = newRequestContextWithURLValues(w, req, params)
c = newRequestContextWithParams(w, req, map[string]string{"method": "key"})

didRouter.ListDIDsByMethod(c)

Expand All @@ -576,12 +574,11 @@ func TestDIDAPI(t *testing.T) {

w := httptest.NewRecorder()
params := url.Values{
"method": []string{"key"},
"pageSize": []string{"1"},
}
req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key?"+params.Encode(), nil)

c := newRequestContextWithURLValues(w, req, params)
c := newRequestContextWithParams(w, req, map[string]string{"method": "key"})
didRouter.ListDIDsByMethod(c)
assert.True(tt, util.Is2xxResponse(w.Result().StatusCode))

Expand All @@ -595,7 +592,7 @@ func TestDIDAPI(t *testing.T) {
params["pageToken"] = []string{listDIDsByMethodResponse.NextPageToken}
params["deleted"] = []string{"true"}
req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key?"+params.Encode(), nil)
c = newRequestContextWithURLValues(w, req, params)
c = newRequestContextWithParams(w, req, map[string]string{"method": "key"})
didRouter.ListDIDsByMethod(c)
assert.Equal(tt, http.StatusBadRequest, w.Result().StatusCode)
assert.Contains(tt, w.Body.String(), "page token must be for the same query")
Expand Down
12 changes: 6 additions & 6 deletions pkg/server/server_presentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func TestPresentationAPI(t *testing.T) {
"pageSize": []string{"-1"},
}
req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/submissions?"+badParams.Encode(), nil)
c := newRequestContextWithURLValues(w, req, badParams)
c := newRequestContext(w, req)
pRouter.ListSubmissions(c)

assert.Contains(tttt, w.Body.String(), "'pageSize' must be greater than 0")
Expand All @@ -562,7 +562,7 @@ func TestPresentationAPI(t *testing.T) {
"pageToken": []string{"made up token"},
}
req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/submissions?"+badParams.Encode(), nil)
c := newRequestContextWithURLValues(w, req, badParams)
c := newRequestContext(w, req)
pRouter.ListSubmissions(c)

assert.Contains(tttt, w.Body.String(), "token value cannot be decoded")
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestPresentationAPI(t *testing.T) {
"pageSize": []string{"1"},
}
req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/submissions?"+params.Encode(), nil)
c := newRequestContextWithURLValues(w, req, params)
c := newRequestContext(w, req)

pRouter.ListSubmissions(c)

Expand All @@ -616,7 +616,7 @@ func TestPresentationAPI(t *testing.T) {
w = httptest.NewRecorder()
params["pageToken"] = []string{listSubmissionResponse.NextPageToken}
req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/submissions?"+params.Encode(), nil)
c = newRequestContextWithURLValues(w, req, params)
c = newRequestContext(w, req)

pRouter.ListSubmissions(c)

Expand Down Expand Up @@ -662,7 +662,7 @@ func TestPresentationAPI(t *testing.T) {
"pageSize": []string{"1"},
}
req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/submissions?"+params.Encode(), nil)
c := newRequestContextWithURLValues(w, req, params)
c := newRequestContext(w, req)

pRouter.ListSubmissions(c)

Expand All @@ -676,7 +676,7 @@ func TestPresentationAPI(t *testing.T) {
params["pageToken"] = []string{listSubmissionResponse.NextPageToken}
params["filter"] = []string{"status=\"pending\""}
req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/submissions?"+params.Encode(), nil)
c = newRequestContextWithURLValues(w, req, params)
c = newRequestContext(w, req)

pRouter.ListSubmissions(c)
assert.Equal(tttt, http.StatusBadRequest, w.Result().StatusCode)
Expand Down
29 changes: 7 additions & 22 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,32 @@ import (
"io"
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"github.com/TBD54566975/ssi-sdk/credential/exchange"
"github.com/gin-gonic/gin"

"github.com/tbd54566975/ssi-service/internal/util"
"github.com/tbd54566975/ssi-service/pkg/service/issuance"
"github.com/tbd54566975/ssi-service/pkg/service/manifest/model"
"github.com/tbd54566975/ssi-service/pkg/service/webhook"
"github.com/tbd54566975/ssi-service/pkg/testutil"

manifestsdk "github.com/TBD54566975/ssi-sdk/credential/manifest"
"github.com/TBD54566975/ssi-sdk/crypto"
"github.com/gin-gonic/gin"
"github.com/goccy/go-json"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

credmodel "github.com/tbd54566975/ssi-service/internal/credential"

"github.com/tbd54566975/ssi-service/config"
credmodel "github.com/tbd54566975/ssi-service/internal/credential"
"github.com/tbd54566975/ssi-service/internal/util"
"github.com/tbd54566975/ssi-service/pkg/server/router"
"github.com/tbd54566975/ssi-service/pkg/service/credential"
"github.com/tbd54566975/ssi-service/pkg/service/did"
svcframework "github.com/tbd54566975/ssi-service/pkg/service/framework"
"github.com/tbd54566975/ssi-service/pkg/service/issuance"
"github.com/tbd54566975/ssi-service/pkg/service/keystore"
"github.com/tbd54566975/ssi-service/pkg/service/manifest"
"github.com/tbd54566975/ssi-service/pkg/service/manifest/model"
"github.com/tbd54566975/ssi-service/pkg/service/schema"
"github.com/tbd54566975/ssi-service/pkg/service/webhook"
"github.com/tbd54566975/ssi-service/pkg/storage"
"github.com/tbd54566975/ssi-service/pkg/testutil"
)

const (
Expand Down Expand Up @@ -131,16 +126,6 @@ func newRequestContextWithParams(w http.ResponseWriter, req *http.Request, param
return c
}

func newRequestContextWithURLValues(w http.ResponseWriter, req *http.Request, params url.Values) *gin.Context {
c := newRequestContext(w, req)
for k, vs := range params {
for _, v := range vs {
c.AddParam(k, v)
}
}
return c
}

func getValidCreateManifestRequest(issuerDID, verificationMethodID, schemaID string) router.CreateManifestRequest {
return router.CreateManifestRequest{
IssuerDID: issuerDID,
Expand Down

0 comments on commit 740a33a

Please sign in to comment.