diff --git a/Makefile b/Makefile index e6236db3..48aed952 100644 --- a/Makefile +++ b/Makefile @@ -130,10 +130,10 @@ tidy: ############################################################################### unit-tests: - cd tests/unit && ginkgo -r --tags unit --race + cd tests/unit && ginkgo -r --tags unit --race --keep-going integration-tests: - cd tests/integration/rest && ginkgo -r --tags integration --race + cd tests/integration/rest && ginkgo -r --tags integration --race --keep-going lint: golangci-lint run --config .github/linters/.golangci.yaml diff --git a/docker/Dockerfile b/docker/Dockerfile index 1b7e1ecf..93afb0d9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,7 +2,7 @@ ### STAGE 1: Build cheqd did-resolver binary pre-requisites ### ##################################################################### -FROM golang:1.18-alpine AS builder +FROM golang:1.20-alpine AS builder # Install minimum necessary dependencies ENV PACKAGES make git bash linux-headers findutils diff --git a/go.mod b/go.mod index f8aca37d..1df490b0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cheqd/did-resolver -go 1.18 +go 1.20 require ( github.com/cheqd/cheqd-node/api/v2 v2.1.0 diff --git a/tests/integration/rest/diddoc/query/version_time/negative_test.go b/tests/integration/rest/diddoc/query/version_time/negative_test.go index a20bb3a8..d5fb032f 100644 --- a/tests/integration/rest/diddoc/query/version_time/negative_test.go +++ b/tests/integration/rest/diddoc/query/version_time/negative_test.go @@ -5,6 +5,7 @@ package versionTime import ( "encoding/json" "fmt" + "net/url" testconstants "github.com/cheqd/did-resolver/tests/constants" utils "github.com/cheqd/did-resolver/tests/integration/rest" @@ -57,6 +58,33 @@ var _ = DescribeTable("Negative: Get DIDDoc with versionTime query", func(testCa }, ), + Entry( + "cannot get DIDDoc with not supported format of versionTime query parameter (not supported format)", + utils.NegativeTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("06/03/2023 09:36:54"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedResult: types.DidResolution{ + Context: "", + ResolutionMetadata: types.ResolutionMetadata{ + ContentType: types.DIDJSONLD, + ResolutionError: "invalidDidUrl", + DidProperties: types.DidProperties{ + DidString: testconstants.SeveralVersionsDID, + MethodSpecificId: testconstants.SeveralVersionsDIDIdentifier, + Method: testconstants.ValidMethod, + }, + }, + Did: nil, + Metadata: types.ResolutionDidDocMetadata{}, + }, + ExpectedStatusCode: types.InvalidDidUrlHttpCode, + }, + ), + Entry( "cannot get DIDDoc with an invalid versionTime query parameter", utils.NegativeTestCase{ diff --git a/tests/integration/rest/diddoc/query/version_time/positive_test.go b/tests/integration/rest/diddoc/query/version_time/positive_test.go index ff890ce8..c59e1b25 100644 --- a/tests/integration/rest/diddoc/query/version_time/positive_test.go +++ b/tests/integration/rest/diddoc/query/version_time/positive_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/http" + "net/url" testconstants "github.com/cheqd/did-resolver/tests/constants" utils "github.com/cheqd/did-resolver/tests/integration/rest" @@ -34,7 +35,175 @@ var _ = DescribeTable("Positive: Get DIDDoc with versionTime query", func(testCa }, Entry( - "can get DIDDoc with versionTime query parameter", + "can get DIDDoc with an old 16 characters INDY style DID and versionTime query parameter", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.OldIndy16CharStyleTestnetDid, + "2022-10-13T06:09:04Z", + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_16_old_indy_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with an old 32 characters INDY style DID and versionTime query parameter", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.OldIndy32CharStyleTestnetDid, + "2022-10-12T08:57:25Z", + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_32_old_indy_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (Layout format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("03/06 09:39:50AM '23 +0000"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (ANSIC format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("Mon Mar 06 09:39:50 2023"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (UnixDate format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("Mon Mar 06 09:39:50 UTC 2023"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (RubyDate format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("Mon Mar 06 09:39:50 +0000 2023"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (RFC822 format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("06 Mar 23 09:40 UTC"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (RFC822Z format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("06 Mar 23 09:40 +0000"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (RFC850 format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("Monday, 06-Mar-23 09:39:50 UTC"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (RFC1123 format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("Mon, 06 Mar 2023 09:39:50 UTC"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (RFC1123Z format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + url.QueryEscape("Mon, 06 Mar 2023 09:39:50 +0000"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (RFC3339 format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", + testconstants.SeveralVersionsDID, + "2023-03-06T09:39:50Z", + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get DIDDoc with versionTime query parameter (RFC3339Nano format)", utils.PositiveTestCase{ DidURL: fmt.Sprintf( "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", @@ -48,29 +217,29 @@ var _ = DescribeTable("Positive: Get DIDDoc with versionTime query", func(testCa ), Entry( - "can get DIDDoc with an old 16 characters INDY style DID and versionTime query parameter", + "can get DIDDoc with versionTime query parameter (DateTime format)", utils.PositiveTestCase{ DidURL: fmt.Sprintf( "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", - testconstants.OldIndy16CharStyleTestnetDid, - "2022-10-13T06:09:04Z", + testconstants.SeveralVersionsDID, + url.QueryEscape("2023-03-06 09:39:50"), ), ResolutionType: testconstants.DefaultResolutionType, - ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_16_old_indy_did.json", + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", ExpectedStatusCode: http.StatusOK, }, ), Entry( - "can get DIDDoc with an old 32 characters INDY style DID and versionTime query parameter", + "can get DIDDoc with versionTime query parameter (DateOnly format)", utils.PositiveTestCase{ DidURL: fmt.Sprintf( "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", - testconstants.OldIndy32CharStyleTestnetDid, - "2022-10-12T08:57:25Z", + testconstants.SeveralVersionsDID, + "2023-03-07", ), ResolutionType: testconstants.DefaultResolutionType, - ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_32_old_indy_did.json", + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_date_did.json", ExpectedStatusCode: http.StatusOK, }, ), diff --git a/tests/integration/rest/resource/query/resource_version_time/negative_test.go b/tests/integration/rest/resource/query/resource_version_time/negative_test.go index 793ea8af..56650e61 100644 --- a/tests/integration/rest/resource/query/resource_version_time/negative_test.go +++ b/tests/integration/rest/resource/query/resource_version_time/negative_test.go @@ -5,6 +5,7 @@ package resource_version_time_test import ( "encoding/json" "fmt" + "net/url" testconstants "github.com/cheqd/did-resolver/tests/constants" utils "github.com/cheqd/did-resolver/tests/integration/rest" @@ -36,16 +37,16 @@ var _ = DescribeTable("Negative: Get Collection of Resources with resourceVersio "cannot get collection of resources with not existent resourceVersionTime query parameter", utils.NegativeTestCase{ DidURL: fmt.Sprintf( - "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s", + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", testconstants.UUIDStyleTestnetDid, - "2023-03-06T09:36:56.56204903Z", + "2023-01-25T12:04:51Z", ), ResolutionType: string(types.DIDJSONLD), ExpectedResult: utils.DereferencingResult{ Context: "", DereferencingMetadata: types.DereferencingMetadata{ ContentType: types.DIDJSONLD, - ResolutionError: "representationNotSupported", + ResolutionError: "notFound", DidProperties: types.DidProperties{ DidString: testconstants.UUIDStyleTestnetDid, MethodSpecificId: testconstants.UUIDStyleTestnetId, @@ -55,7 +56,34 @@ var _ = DescribeTable("Negative: Get Collection of Resources with resourceVersio ContentStream: nil, Metadata: types.ResolutionDidDocMetadata{}, }, - ExpectedStatusCode: errors.RepresentationNotSupportedHttpCode, // it should be notFound + ExpectedStatusCode: errors.NotFoundHttpCode, // it should be notFound + }, + ), + + Entry( + "cannot get collection of resources with not supported format of resourceVersionTime query parameter", + utils.NegativeTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("06/03/2023 09:36:56"), + ), + ResolutionType: string(types.DIDJSONLD), + ExpectedResult: utils.DereferencingResult{ + Context: "", + DereferencingMetadata: types.DereferencingMetadata{ + ContentType: types.DIDJSONLD, + ResolutionError: "invalidDidUrl", + DidProperties: types.DidProperties{ + DidString: testconstants.UUIDStyleTestnetDid, + MethodSpecificId: testconstants.UUIDStyleTestnetId, + Method: testconstants.ValidMethod, + }, + }, + ContentStream: nil, + Metadata: types.ResolutionDidDocMetadata{}, + }, + ExpectedStatusCode: errors.InvalidDidUrlHttpCode, }, ), diff --git a/tests/integration/rest/resource/query/resource_version_time/positive_test.go b/tests/integration/rest/resource/query/resource_version_time/positive_test.go index 157c1829..ab895a4c 100644 --- a/tests/integration/rest/resource/query/resource_version_time/positive_test.go +++ b/tests/integration/rest/resource/query/resource_version_time/positive_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/http" + "net/url" testconstants "github.com/cheqd/did-resolver/tests/constants" utils "github.com/cheqd/did-resolver/tests/integration/rest" @@ -33,8 +34,151 @@ var _ = DescribeTable("Positive: Get Collection of Resources with resourceVersio utils.AssertDidDereferencing(expectedDidDereferencing, receivedDidDereferencing) }, + // TODO: add unit test for testing get resource with an old 16 characters INDY style DID + // and resourceVersionTime query parameter. + + Entry( + "can get resource with an old 32 characters INDY style DID and resourceVersionTime query parameter", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.OldIndy32CharStyleTestnetDid, + "2022-10-12T08:57:31Z", + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource_32_indy_did.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (Layout format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("01/25 00:08:40PM '23 +0000"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (ANSIC format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("Wed Jan 25 12:08:40 2023"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (UnixDate format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("Wed Jan 25 12:08:40 UTC 2023"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (RubyDate format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("Wed Jan 25 12:08:40 +0000 2023"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (RFC822 format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("25 Jan 23 12:09 UTC"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (RFC822Z format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("25 Jan 23 12:09 +0000"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (RFC850 format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("Wednesday, 25-Jan-23 12:08:40 UTC"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (RFC1123 format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("Wed, 25 Jan 2023 12:08:40 UTC"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (RFC1123Z format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("Wed, 25 Jan 2023 12:08:40 +0000"), + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + Entry( - "can get collection of resources with an existent resourceVersionTime query parameter", + "can get collection of resources with an existent resourceVersionTime query parameter (RFC3339 format)", utils.PositiveTestCase{ DidURL: fmt.Sprintf( "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", @@ -47,19 +191,44 @@ var _ = DescribeTable("Positive: Get Collection of Resources with resourceVersio }, ), - // TODO: add unit test for testing get resource with an old 16 characters INDY style DID - // and resourceVersionTime query parameter. + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (RFC3339Nano format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + "2023-01-25T12:08:40.0Z", + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), Entry( - "can get resource with an old 32 characters INDY style DID and resourceVersionTime query parameter", + "can get collection of resources with an existent resourceVersionTime query parameter (DateTime format)", utils.PositiveTestCase{ DidURL: fmt.Sprintf( "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", - testconstants.OldIndy32CharStyleTestnetDid, - "2022-10-12T08:57:31Z", + testconstants.UUIDStyleTestnetDid, + url.QueryEscape("2023-01-25 12:08:40"), ), ResolutionType: testconstants.DefaultResolutionType, - ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource_32_indy_did.json", + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", + ExpectedStatusCode: http.StatusOK, + }, + ), + + Entry( + "can get collection of resources with an existent resourceVersionTime query parameter (DateOnly format)", + utils.PositiveTestCase{ + DidURL: fmt.Sprintf( + "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", + testconstants.UUIDStyleTestnetDid, + "2023-01-26", + ), + ResolutionType: testconstants.DefaultResolutionType, + ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", ExpectedStatusCode: http.StatusOK, }, ), diff --git a/tests/integration/rest/testdata/query/version_time/diddoc_version_time_date_did.json b/tests/integration/rest/testdata/query/version_time/diddoc_version_time_date_did.json new file mode 100644 index 00000000..70c1112d --- /dev/null +++ b/tests/integration/rest/testdata/query/version_time/diddoc_version_time_date_did.json @@ -0,0 +1,60 @@ +{ + "@context": "https://w3id.org/did-resolution/v1", + "didResolutionMetadata": { + "contentType": "application/did+ld+json", + "retrieved": "2023-04-24T10:48:50Z", + "did": { + "didString": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c", + "methodSpecificId": "b5d70adf-31ca-4662-aa10-d3a54cd8f06c", + "method": "cheqd" + } + }, + "didDocument": { + "@context": [ + "https://www.w3.org/ns/did/v1", + "https://w3id.org/security/suites/ed25519-2018/v1" + ], + "id": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c", + "verificationMethod": [ + { + "id": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c#key-1", + "type": "Ed25519VerificationKey2018", + "controller": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c", + "publicKeyBase58": "BpVGbTeT26LipAdk26DBZrmJx2939i9gZS5VxGt1zZQ6" + } + ], + "authentication": [ + "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c#key-1" + ], + "service": [ + { + "id": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c#bar", + "type": "LinkedDomains", + "serviceEndpoint": [ + "https://bar.example.com" + ] + } + ] + }, + "didDocumentMetadata": { + "created": "2023-03-06T09:36:55Z", + "updated": "2023-03-06T09:59:22Z", + "deactivated": true, + "versionId": "f790c9b9-4817-4b31-be43-b198e6e18071", + "linkedResourceMetadata": [ + { + "resourceURI": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c/resources/5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", + "resourceCollectionId": "b5d70adf-31ca-4662-aa10-d3a54cd8f06c", + "resourceId": "5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", + "resourceName": "TestResource", + "resourceType": "TestType", + "mediaType": "text/plain; charset=utf-8", + "resourceVersion": "1.0", + "created": "2023-03-06T09:53:44Z", + "checksum": "64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c", + "previousVersionId": null, + "nextVersionId": null + } + ] + } +} diff --git a/utils/parse_time.go b/utils/parse_time.go index 4497421c..a344a8f6 100644 --- a/utils/parse_time.go +++ b/utils/parse_time.go @@ -1,6 +1,9 @@ package utils -import "time" +import ( + "fmt" + "time" +) func ParseFromStringTimeToGoTime(timeString string) (time.Time, error) { // If timeString is empty return default nullable time value (0001-01-01 00:00:00 +0000 UTC) @@ -8,13 +11,38 @@ func ParseFromStringTimeToGoTime(timeString string) (time.Time, error) { return time.Time{}, nil } - t, err := time.Parse(time.RFC3339, timeString) - if err == nil { - return t, nil - } - t, err = time.Parse(time.RFC3339Nano, timeString) + t, err := parseTimeString(timeString) if err == nil { return t, nil } + return time.Time{}, err } + +func parseTimeString(timeString string) (time.Time, error) { + formats := []string{ + time.Layout, + time.ANSIC, + time.UnixDate, + time.RubyDate, + time.RFC822, + time.RFC822Z, + time.RFC850, + time.RFC1123, + time.RFC1123Z, + time.RFC3339, + time.RFC3339Nano, + time.DateTime, + time.DateOnly, + } + + // Try parsing the date using different formats + for _, format := range formats { + parsedTime, err := time.Parse(format, timeString) + if err == nil { + return parsedTime.UTC(), nil + } + } + + return time.Time{}, fmt.Errorf("unable to parse date string") +}