From 86ee756755aacb5193672f125e865cf524b67877 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov <99400260+abdulla-ashurov@users.noreply.github.com> Date: Wed, 12 Apr 2023 14:23:06 +0500 Subject: [PATCH] fix: Change `representationNotSupported` error to `invalidDidUrl` if 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. --- services/diddoc/diddoc_query.go | 2 +- .../rest/support_query_negative_test.go | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/integration/rest/support_query_negative_test.go diff --git a/services/diddoc/diddoc_query.go b/services/diddoc/diddoc_query.go index fe3ef3c1..29fbc5d9 100644 --- a/services/diddoc/diddoc_query.go +++ b/services/diddoc/diddoc_query.go @@ -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 diff --git a/tests/integration/rest/support_query_negative_test.go b/tests/integration/rest/support_query_negative_test.go new file mode 100644 index 00000000..09647df8 --- /dev/null +++ b/tests/integration/rest/support_query_negative_test.go @@ -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, + }, + ), +)