From e337a4f1109f3a9875d0cb7f559c2711d24b8ef8 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 16 Jun 2023 18:29:55 +0500 Subject: [PATCH 01/16] Add implementation for supporting different formats of date in versionTime and resourceVersionTime queries. --- utils/parse_time.go | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/utils/parse_time.go b/utils/parse_time.go index 4497421c..17793566 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,37 @@ 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 := parseDateString(timeString) if err == nil { return t, nil } + return time.Time{}, err } + +func parseDateString(timeString string) (time.Time, error) { + formats := []string{ + time.Layout, + time.ANSIC, + time.UnixDate, + time.RubyDate, + time.RFC822, + 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, nil + } + } + + return time.Time{}, fmt.Errorf("unable to parse date string") +} From 19f56bbf582b4620bf257f0030a651bc72b08d21 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 16 Jun 2023 19:40:36 +0500 Subject: [PATCH 02/16] Add positive integration tests for versionTime query parameter. --- .../query/version_time/positive_test.go | 60 ++++++++++++++++--- 1 file changed, 51 insertions(+), 9 deletions(-) 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..1092ff8c 100644 --- a/tests/integration/rest/diddoc/query/version_time/positive_test.go +++ b/tests/integration/rest/diddoc/query/version_time/positive_test.go @@ -34,7 +34,49 @@ 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 (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 +90,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, + "2023-03-06 09:39:50Z", ), 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_did.json", ExpectedStatusCode: http.StatusOK, }, ), From 41322262ce1ed0fc3d59afa208af2df3031c4866 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 16 Jun 2023 19:40:56 +0500 Subject: [PATCH 03/16] Remove unused date formats. --- utils/parse_time.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/utils/parse_time.go b/utils/parse_time.go index 17793566..7cba1383 100644 --- a/utils/parse_time.go +++ b/utils/parse_time.go @@ -21,14 +21,6 @@ func ParseFromStringTimeToGoTime(timeString string) (time.Time, error) { func parseDateString(timeString string) (time.Time, error) { formats := []string{ - time.Layout, - time.ANSIC, - time.UnixDate, - time.RubyDate, - time.RFC822, - time.RFC850, - time.RFC1123, - time.RFC1123Z, time.RFC3339, time.RFC3339Nano, time.DateTime, From d8c6eaeee6dbbf5e5571b5e16e4bec3e3fc7820f Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 16 Jun 2023 20:57:15 +0500 Subject: [PATCH 04/16] Refactor code. --- utils/parse_time.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/parse_time.go b/utils/parse_time.go index 7cba1383..f67bf66f 100644 --- a/utils/parse_time.go +++ b/utils/parse_time.go @@ -23,8 +23,8 @@ func parseDateString(timeString string) (time.Time, error) { formats := []string{ time.RFC3339, time.RFC3339Nano, - time.DateTime, - time.DateOnly, + "2006-01-02 15:04:05", + "2006-01-02", } // Try parsing the date using different formats From 701ade4e600b0f2ad123b700b19294c1befebe62 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 16 Jun 2023 21:32:32 +0500 Subject: [PATCH 05/16] Update positive version time integration tests. --- tests/constants/constants.go | 5 +- .../query/version_time/positive_test.go | 5 +- .../diddoc_version_time_date_did.json | 60 +++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 tests/integration/rest/testdata/query/version_time/diddoc_version_time_date_did.json diff --git a/tests/constants/constants.go b/tests/constants/constants.go index f98a084c..46e6e3d0 100644 --- a/tests/constants/constants.go +++ b/tests/constants/constants.go @@ -168,4 +168,7 @@ var ( var DIDStructure = "did:%s:%s:%s" -var HashTag = "\u0023" +var ( + HashTag = "\u0023" + Space = "\u0020" +) 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 1092ff8c..7424838b 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" @@ -95,7 +96,7 @@ var _ = DescribeTable("Positive: Get DIDDoc with versionTime query", func(testCa DidURL: fmt.Sprintf( "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", testconstants.SeveralVersionsDID, - "2023-03-06 09:39:50Z", + "2023-03-06"+url.PathEscape(testconstants.HashTag)+"09:39:50Z", ), ResolutionType: testconstants.DefaultResolutionType, ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", @@ -112,7 +113,7 @@ var _ = DescribeTable("Positive: Get DIDDoc with versionTime query", func(testCa "2023-03-07", ), ResolutionType: testconstants.DefaultResolutionType, - ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", + ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_date_did.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 + } + ] + } +} From ba34f9f4d33da766751ea8156101546fbd007256 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Sun, 18 Jun 2023 15:28:14 +0500 Subject: [PATCH 06/16] Update integration test. --- .../integration/rest/diddoc/query/version_time/positive_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7424838b..728563ed 100644 --- a/tests/integration/rest/diddoc/query/version_time/positive_test.go +++ b/tests/integration/rest/diddoc/query/version_time/positive_test.go @@ -96,7 +96,7 @@ var _ = DescribeTable("Positive: Get DIDDoc with versionTime query", func(testCa DidURL: fmt.Sprintf( "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", testconstants.SeveralVersionsDID, - "2023-03-06"+url.PathEscape(testconstants.HashTag)+"09:39:50Z", + "2023-03-06"+url.PathEscape(testconstants.Space)+"09:39:50", ), ResolutionType: testconstants.DefaultResolutionType, ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", From e5abb6709707ee450493409e677952edcb6ecff6 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Sun, 18 Jun 2023 15:45:21 +0500 Subject: [PATCH 07/16] Add positive integration tests for testing resourceVersionTime query. --- .../resource_version_time/positive_test.go | 57 ++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) 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..7e52fe8d 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,25 @@ 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", + "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 +65,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, + "2023-01-25"+url.PathEscape(testconstants.Space)+"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, }, ), From d8a74a63b76a533f3c8c45d0097d44cb3c7d9f0c Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Sun, 18 Jun 2023 15:45:43 +0500 Subject: [PATCH 08/16] Update Makefile. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 04653b67ead1cf038a638c9d3e8ff15627cf0207 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 19 Jun 2023 18:45:50 +0500 Subject: [PATCH 09/16] Add implementation for supporting more date types: - Layout - ANSIC - UnixDate - RubyDate - RFC822 - RFC822Z - RFC850 - RFC1123 - RFC1123Z --- utils/parse_time.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utils/parse_time.go b/utils/parse_time.go index f67bf66f..894da11b 100644 --- a/utils/parse_time.go +++ b/utils/parse_time.go @@ -21,6 +21,15 @@ func ParseFromStringTimeToGoTime(timeString string) (time.Time, error) { func parseDateString(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, "2006-01-02 15:04:05", @@ -31,7 +40,7 @@ func parseDateString(timeString string) (time.Time, error) { for _, format := range formats { parsedTime, err := time.Parse(format, timeString) if err == nil { - return parsedTime, nil + return parsedTime.UTC(), nil } } From 0ac0fb2437321a10b08e3e4b80371b31004c5465 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 19 Jun 2023 18:46:30 +0500 Subject: [PATCH 10/16] Add more positive integration test for testing different date formats. --- .../query/version_time/positive_test.go | 128 +++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) 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 728563ed..c59e1b25 100644 --- a/tests/integration/rest/diddoc/query/version_time/positive_test.go +++ b/tests/integration/rest/diddoc/query/version_time/positive_test.go @@ -62,6 +62,132 @@ var _ = DescribeTable("Positive: Get DIDDoc with versionTime query", func(testCa }, ), + 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{ @@ -96,7 +222,7 @@ var _ = DescribeTable("Positive: Get DIDDoc with versionTime query", func(testCa DidURL: fmt.Sprintf( "http://localhost:8080/1.0/identifiers/%s?versionTime=%s", testconstants.SeveralVersionsDID, - "2023-03-06"+url.PathEscape(testconstants.Space)+"09:39:50", + url.QueryEscape("2023-03-06 09:39:50"), ), ResolutionType: testconstants.DefaultResolutionType, ExpectedJSONPath: "../../../testdata/query/version_time/diddoc_version_time_did.json", From a3410a12b359c4738ed9deb42d3ed723083dd5ad Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 19 Jun 2023 19:13:55 +0500 Subject: [PATCH 11/16] Refactor code. --- tests/constants/constants.go | 5 +---- .../resource/query/resource_version_time/positive_test.go | 2 +- utils/parse_time.go | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/constants/constants.go b/tests/constants/constants.go index 46e6e3d0..f98a084c 100644 --- a/tests/constants/constants.go +++ b/tests/constants/constants.go @@ -168,7 +168,4 @@ var ( var DIDStructure = "did:%s:%s:%s" -var ( - HashTag = "\u0023" - Space = "\u0020" -) +var HashTag = "\u0023" 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 7e52fe8d..0fd702d6 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 @@ -85,7 +85,7 @@ var _ = DescribeTable("Positive: Get Collection of Resources with resourceVersio DidURL: fmt.Sprintf( "http://localhost:8080/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", testconstants.UUIDStyleTestnetDid, - "2023-01-25"+url.PathEscape(testconstants.Space)+"12:08:40", + url.QueryEscape("2023-01-25 12:08:40"), ), ResolutionType: testconstants.DefaultResolutionType, ExpectedJSONPath: "../../../testdata/query/resource_version_time/resource.json", diff --git a/utils/parse_time.go b/utils/parse_time.go index 894da11b..4619e3bc 100644 --- a/utils/parse_time.go +++ b/utils/parse_time.go @@ -11,7 +11,7 @@ func ParseFromStringTimeToGoTime(timeString string) (time.Time, error) { return time.Time{}, nil } - t, err := parseDateString(timeString) + t, err := parseTimeString(timeString) if err == nil { return t, nil } @@ -19,7 +19,7 @@ func ParseFromStringTimeToGoTime(timeString string) (time.Time, error) { return time.Time{}, err } -func parseDateString(timeString string) (time.Time, error) { +func parseTimeString(timeString string) (time.Time, error) { formats := []string{ time.Layout, time.ANSIC, From b14c8368689a8832ab8f5c429038ce1e1f29fae6 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 19 Jun 2023 19:58:30 +0500 Subject: [PATCH 12/16] Add positive integration tests for testing resourceVersionTime query with different date formats. --- .../resource_version_time/positive_test.go | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) 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 0fd702d6..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 @@ -51,6 +51,132 @@ var _ = DescribeTable("Positive: Get Collection of Resources with resourceVersio }, ), + 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 (RFC3339 format)", utils.PositiveTestCase{ From 931645f18e749669b1f2081095cab00a4f9cff1d Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 19 Jun 2023 22:08:58 +0500 Subject: [PATCH 13/16] Add negative integration tests for testing versionTime and resourceVersionTime queries with an invalid date format. --- .../query/version_time/negative_test.go | 28 +++++++++++++++ .../resource_version_time/negative_test.go | 36 ++++++++++++++++--- 2 files changed, 60 insertions(+), 4 deletions(-) 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/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, }, ), From f0185cdc6ed217f596810524d2d60c65b46081dc Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 19 Jun 2023 22:12:03 +0500 Subject: [PATCH 14/16] Use constants variables instead of magic strings. --- utils/parse_time.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/parse_time.go b/utils/parse_time.go index 4619e3bc..a344a8f6 100644 --- a/utils/parse_time.go +++ b/utils/parse_time.go @@ -32,8 +32,8 @@ func parseTimeString(timeString string) (time.Time, error) { time.RFC1123Z, time.RFC3339, time.RFC3339Nano, - "2006-01-02 15:04:05", - "2006-01-02", + time.DateTime, + time.DateOnly, } // Try parsing the date using different formats From 022a0b86b4dfd82988330e510695f886514d057c Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 19 Jun 2023 22:27:51 +0500 Subject: [PATCH 15/16] Update golang version in Dockerfile. --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From cbeeeb557459ee6ca017e797099c794312de14c4 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 19 Jun 2023 22:29:01 +0500 Subject: [PATCH 16/16] Bump golang version from v1.18 to v1.20 in go.mod. --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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