From 931645f18e749669b1f2081095cab00a4f9cff1d Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 19 Jun 2023 22:08:58 +0500 Subject: [PATCH] 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, }, ),