Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support date only format with versionTime, resourceTime query parameters [DEV-2807] #165

Merged
merged 17 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/rest/diddoc/query/version_time/negative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
187 changes: 178 additions & 9 deletions tests/integration/rest/diddoc/query/version_time/positive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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,
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
),

Expand Down
Loading