Skip to content

Commit

Permalink
fix: Change representationNotSupported error to invalidDidUrl if …
Browse files Browse the repository at this point in the history
…query is wrong or not supported [DEV-2401] (#135)

* Add integration test data payloads.

* Add integration test constants.

* Create test runner for running integration tests.

* Add positive integration tests for getting DIDDoc.

* Add negative integration tests for getting DIDDoc.

* Update go.mod and go.sum files.

* Move DID document payloads to another folder.

* Add did#fragment query payloads for integration
tests.

* Rename testCase member variable:
- from "expectedDIDResolution" to "expectedDidResolution";
- from "receivedDIDResolution" to "receivedDidResolution";
- from "expectedDIDResolution" to "expectedDidResolution".

* Add positive and integration tests for testing API
that gets DID#fragment.

* Fix golangci-lint mistakes.

* Add build tag for building integration tests.

* Fix golangci-lint mistakes.

* Add DIDDoc version payloads for using in
integration tests.

* Add DIDDoc version metadata payloads for using in
integration tests.

* Add integration tests for testing resourceMetadata

* Add integration tests for testing collection of
resources API.

* Add integration tests for testing resolver resource data
request.

* Refactor integration tests.

* Add integration tests for testing get DIDDoc
versions API.

* Add integration tests for testing get DIDDoc
version API.

* Add integration tests for testing get DIDDoc
version metadata API.

* Add integration tests for testing how is working
redirect when we try to get different API with old Indy style DID.

* Refactor and update integration tests.

* Remove an old integration tests.

* Update integration tests.

* Update integration tests for GitHub actions.

* Update GitHub action test.yml file.

* Add integration tests report file to .gitignore.

* Update test.yml

* DIDDoc version should return in resolution format.

* Uncomment integration tests.

* Add integration tests for testing accept header.

* Refactor integration tests.

* Add integration tests for testing accept-encoding
header.

* Rename folder name from "unit-tests" to "unit".

* Update test.yml file.

* Restructure integration tests folder structure.

* Remove an unused ProcessDIDRequest method.

* Move test from did_doc_service and
resource_dereferencing_service to particular handlers.

* Use constant variables instead of a header strings

* Add unit tests for testing how works a redirect
old 16/32 characters Indy style DIDs.

* Re structure unit tests.

* Add integration build flag for test_suite_test.go.

* Refactor unit tests.

* Add more unit tests for testing ledger services.

* Change `representationNotSupported` error to
`invalidDidUrl` if query is wrong or not supported.

* Add integration tests for testing get resolution
result with an invalid query.

* Change from unit to integration go build flag.

* Fix integration test mistake.

* Add HTTP binding constants for using tests.

* Correct the names of the integration test cases.

* Add constant variables for using integration tests
instead of magic strings.

* Fix type mistakes.

* Fix golangci-lint mistakes.

* Update integration tests.

* Update unit test runner command in GitHub actions.

* Update integration tests.
  • Loading branch information
abdulla-ashurov committed Apr 12, 2023
1 parent bd4ea50 commit 86ee756
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion services/diddoc/diddoc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (dd *QueryDIDDocRequestService) SpecificValidation(c services.ResolverConte
// ToDo make list of supported queries
// For now we support only versionId
if dd.Version == "" {
return types.NewRepresentationNotSupportedError(dd.Did, dd.RequestedContentType, nil, dd.IsDereferencing)
return types.NewInvalidDidUrlError(dd.Did, dd.RequestedContentType, nil, dd.IsDereferencing)
}

// Validate that versionId is UUID
Expand Down
60 changes: 60 additions & 0 deletions tests/integration/rest/support_query_negative_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//go:build integration

package rest

import (
"encoding/json"
"fmt"
"net/http"

testconstants "github.com/cheqd/did-resolver/tests/constants"
"github.com/cheqd/did-resolver/types"
"github.com/go-resty/resty/v2"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = DescribeTable("", func(testCase NegativeTestCase) {
client := resty.New()
client.SetRedirectPolicy(resty.NoRedirectPolicy())

resp, err := client.R().
SetHeader("Accept", testCase.ResolutionType).
Get(testCase.DidURL)
Expect(err).To(BeNil())
Expect(testCase.ExpectedStatusCode).To(Equal(resp.StatusCode()))

var receivedDidDereferencing DereferencingResult
Expect(json.Unmarshal(resp.Body(), &receivedDidDereferencing)).To(BeNil())
Expect(testCase.ExpectedStatusCode).To(Equal(resp.StatusCode()))

expectedDidDereferencing := testCase.ExpectedResult.(DereferencingResult)
AssertDidDereferencing(expectedDidDereferencing, receivedDidDereferencing)
},

Entry(
"cannot get resolution result with an invalid query",
NegativeTestCase{
DidURL: fmt.Sprintf(
"http://localhost:8080/1.0/identifiers/%s?invalid_parameter=invalid_value",
testconstants.UUIDStyleTestnetDid,
),
ResolutionType: testconstants.DefaultResolutionType,
ExpectedResult: DereferencingResult{
Context: "",
DereferencingMetadata: types.DereferencingMetadata{
ContentType: types.DIDJSONLD,
ResolutionError: "invalidDidUrl",
DidProperties: types.DidProperties{
DidString: testconstants.UUIDStyleTestnetDid,
MethodSpecificId: "c1685ca0-1f5b-439c-8eb8-5c0e85ab7cd0",
Method: testconstants.ValidMethod,
},
},
ContentStream: nil,
Metadata: types.ResolutionDidDocMetadata{},
},
ExpectedStatusCode: http.StatusBadRequest,
},
),
)

0 comments on commit 86ee756

Please sign in to comment.