generated from cheqd/.github
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
548d6da
commit df4017b
Showing
11 changed files
with
473 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
tests/integration/rest/resource/data_with_metadata/negative_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
//go:build integration | ||
|
||
package data_test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
testconstants "github.com/cheqd/did-resolver/tests/constants" | ||
utils "github.com/cheqd/did-resolver/tests/integration/rest" | ||
"github.com/cheqd/did-resolver/types" | ||
errors "github.com/cheqd/did-resolver/types" | ||
"github.com/go-resty/resty/v2" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = DescribeTable("Negative: Get resource data", func(testCase utils.NegativeTestCase) { | ||
client := resty.New() | ||
|
||
resp, err := client.R(). | ||
SetHeader("Accept", testCase.ResolutionType). | ||
Get(testCase.DidURL) | ||
Expect(err).To(BeNil()) | ||
|
||
var receivedDidDereferencing utils.DereferencingResult | ||
Expect(json.Unmarshal(resp.Body(), &receivedDidDereferencing)).To(BeNil()) | ||
Expect(testCase.ExpectedStatusCode).To(Equal(resp.StatusCode())) | ||
|
||
expectedDidDereferencing := testCase.ExpectedResult.(utils.DereferencingResult) | ||
utils.AssertDidDereferencing(expectedDidDereferencing, receivedDidDereferencing) | ||
}, | ||
|
||
Entry( | ||
"cannot get resource data with not existent DID and a valid resourceId", | ||
utils.NegativeTestCase{ | ||
DidURL: fmt.Sprintf( | ||
"http://%s/1.0/identifiers/%s/resources/%s", | ||
testconstants.TestHostAddress, | ||
testconstants.NotExistentMainnetDid, | ||
testconstants.ValidIdentifier, | ||
), | ||
ResolutionType: string(types.JSONLD) + ";profile=" + string(types.W3IDDIDURL), | ||
ExpectedResult: utils.DereferencingResult{ | ||
Context: "", | ||
DereferencingMetadata: types.DereferencingMetadata{ | ||
ContentType: types.DIDJSONLD, | ||
ResolutionError: "notFound", | ||
DidProperties: types.DidProperties{ | ||
DidString: testconstants.NotExistentMainnetDid, | ||
MethodSpecificId: testconstants.NotExistentIdentifier, | ||
Method: testconstants.ValidMethod, | ||
}, | ||
}, | ||
ContentStream: nil, | ||
Metadata: types.ResolutionDidDocMetadata{}, | ||
}, | ||
ExpectedStatusCode: errors.NotFoundHttpCode, | ||
}, | ||
), | ||
|
||
Entry( | ||
"cannot get resource data with an invalid DID and not existent resourceId", | ||
utils.NegativeTestCase{ | ||
DidURL: fmt.Sprintf( | ||
"http://%s/1.0/identifiers/%s/resources/%s", | ||
testconstants.TestHostAddress, | ||
testconstants.InvalidDid, | ||
testconstants.ValidIdentifier, | ||
), | ||
ResolutionType: string(types.JSONLD) + ";profile=" + string(types.W3IDDIDURL), | ||
ExpectedResult: utils.DereferencingResult{ | ||
Context: "", | ||
DereferencingMetadata: types.DereferencingMetadata{ | ||
ContentType: types.DIDJSONLD, | ||
ResolutionError: "methodNotSupported", | ||
DidProperties: types.DidProperties{ | ||
DidString: testconstants.InvalidDid, | ||
MethodSpecificId: testconstants.InvalidIdentifier, | ||
Method: testconstants.InvalidMethod, | ||
}, | ||
}, | ||
ContentStream: nil, | ||
Metadata: types.ResolutionDidDocMetadata{}, | ||
}, | ||
ExpectedStatusCode: errors.MethodNotSupportedHttpCode, | ||
}, | ||
), | ||
|
||
Entry( | ||
"cannot get resource data with not existent DID and resourceId", | ||
utils.NegativeTestCase{ | ||
DidURL: fmt.Sprintf( | ||
"http://%s/1.0/identifiers/%s/resources/%s", | ||
testconstants.TestHostAddress, | ||
testconstants.NotExistentTestnetDid, | ||
testconstants.NotExistentIdentifier, | ||
), | ||
ResolutionType: string(types.JSONLD) + ";profile=" + string(types.W3IDDIDURL), | ||
ExpectedResult: utils.DereferencingResult{ | ||
Context: "", | ||
DereferencingMetadata: types.DereferencingMetadata{ | ||
ContentType: types.DIDJSONLD, | ||
ResolutionError: "notFound", | ||
DidProperties: types.DidProperties{ | ||
DidString: testconstants.NotExistentTestnetDid, | ||
MethodSpecificId: testconstants.NotExistentIdentifier, | ||
Method: testconstants.ValidMethod, | ||
}, | ||
}, | ||
ContentStream: nil, | ||
Metadata: types.ResolutionDidDocMetadata{}, | ||
}, | ||
ExpectedStatusCode: errors.NotFoundHttpCode, | ||
}, | ||
), | ||
|
||
Entry( | ||
"cannot get resource data with an existent DID and an invalid resourceId", | ||
utils.NegativeTestCase{ | ||
DidURL: fmt.Sprintf( | ||
"http://%s/1.0/identifiers/%s/resources/%s", | ||
testconstants.TestHostAddress, | ||
testconstants.IndyStyleMainnetDid, | ||
testconstants.InvalidIdentifier, | ||
), | ||
ResolutionType: string(types.JSONLD) + ";profile=" + string(types.W3IDDIDURL), | ||
ExpectedResult: utils.DereferencingResult{ | ||
Context: "", | ||
DereferencingMetadata: types.DereferencingMetadata{ | ||
ContentType: types.DIDJSONLD, | ||
ResolutionError: "invalidDidUrl", | ||
DidProperties: types.DidProperties{}, | ||
}, | ||
ContentStream: nil, | ||
Metadata: types.ResolutionDidDocMetadata{}, | ||
}, | ||
ExpectedStatusCode: errors.InvalidDidUrlHttpCode, | ||
}, | ||
), | ||
|
||
Entry( | ||
"cannot get resource data with an existent old 16 characters Indy style DID and an invalid resourceId", | ||
utils.NegativeTestCase{ | ||
DidURL: fmt.Sprintf( | ||
"http://%s/1.0/identifiers/%s/resources/%s", | ||
testconstants.TestHostAddress, | ||
testconstants.OldIndy16CharStyleTestnetDid, | ||
testconstants.InvalidIdentifier, | ||
), | ||
ResolutionType: string(types.JSONLD) + ";profile=" + string(types.W3IDDIDURL), | ||
ExpectedResult: utils.DereferencingResult{ | ||
Context: "", | ||
DereferencingMetadata: types.DereferencingMetadata{ | ||
ContentType: types.DIDJSONLD, | ||
ResolutionError: "invalidDidUrl", | ||
DidProperties: types.DidProperties{}, | ||
}, | ||
ContentStream: nil, | ||
Metadata: types.ResolutionDidDocMetadata{}, | ||
}, | ||
ExpectedStatusCode: errors.InvalidDidUrlHttpCode, | ||
}, | ||
), | ||
|
||
Entry( | ||
"cannot get resource data with an existent old 32 characters Indy style DID and an invalid resourceId", | ||
utils.NegativeTestCase{ | ||
DidURL: fmt.Sprintf( | ||
"http://%s/1.0/identifiers/%s/resources/%s", | ||
testconstants.TestHostAddress, | ||
testconstants.OldIndy32CharStyleTestnetDid, | ||
testconstants.InvalidIdentifier, | ||
), | ||
ResolutionType: string(types.JSONLD) + ";profile=" + string(types.W3IDDIDURL), | ||
ExpectedResult: utils.DereferencingResult{ | ||
Context: "", | ||
DereferencingMetadata: types.DereferencingMetadata{ | ||
ContentType: types.DIDJSONLD, | ||
ResolutionError: "invalidDidUrl", | ||
DidProperties: types.DidProperties{}, | ||
}, | ||
ContentStream: nil, | ||
Metadata: types.ResolutionDidDocMetadata{}, | ||
}, | ||
ExpectedStatusCode: errors.InvalidDidUrlHttpCode, | ||
}, | ||
), | ||
) |
54 changes: 54 additions & 0 deletions
54
tests/integration/rest/resource/data_with_metadata/positive_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//go:build integration | ||
|
||
package data_test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
testconstants "github.com/cheqd/did-resolver/tests/constants" | ||
utils "github.com/cheqd/did-resolver/tests/integration/rest" | ||
"github.com/cheqd/did-resolver/types" | ||
"github.com/go-resty/resty/v2" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = DescribeTable("Positive: Get resource data with metadata", func(testCase utils.PositiveTestCase) { | ||
client := resty.New() | ||
|
||
resp, err := client.R(). | ||
SetHeader("Accept", testCase.ResolutionType). | ||
SetHeader("Accept-Encoding", testCase.EncodingType). | ||
Get(testCase.DidURL) | ||
Expect(err).To(BeNil()) | ||
|
||
var receivedResourceDataWithMetadata any | ||
Expect(json.Unmarshal(resp.Body(), &receivedResourceDataWithMetadata)).To(BeNil()) | ||
Expect(testCase.ExpectedStatusCode).To(Equal(resp.StatusCode())) | ||
|
||
var expectedResourceDataWithMetadata any | ||
Expect(utils.ConvertJsonFileToType(testCase.ExpectedJSONPath, &expectedResourceDataWithMetadata)).To(BeNil()) | ||
|
||
Expect(testCase.ExpectedEncodingType).To(Equal(resp.Header().Get("Content-Encoding"))) | ||
utils.AssertResourceDataWithMetadata(expectedResourceDataWithMetadata, receivedResourceDataWithMetadata) | ||
}, | ||
|
||
Entry( | ||
"can get resource with metadata with an existent DID, and supported JSONLD resolution type and W3DIDUrl dereferencing param", | ||
utils.PositiveTestCase{ | ||
DidURL: fmt.Sprintf( | ||
"http://%s/1.0/identifiers/%s/resources/%s", | ||
testconstants.TestHostAddress, | ||
testconstants.UUIDStyleTestnetDid, | ||
testconstants.UUIDStyleTestnetDidResourceId, | ||
), | ||
ResolutionType: string(types.JSONLD) + ";profile=" + string(types.W3IDDIDURL), | ||
EncodingType: testconstants.DefaultEncodingType, | ||
ExpectedEncodingType: "gzip", | ||
ExpectedJSONPath: "../../testdata/resource_data_with_metadata/resource.json", | ||
ExpectedStatusCode: http.StatusOK, | ||
}, | ||
), | ||
) |
15 changes: 15 additions & 0 deletions
15
tests/integration/rest/resource/data_with_metadata/suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build integration | ||
|
||
package data_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestData(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "[Integration Test]: Resource Data with Metadata") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/integration/rest/testdata/resource_data_with_metadata/resource.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"@context": "https://w3id.org/did-resolution/v1", | ||
"dereferencingMetadata": { | ||
"contentType": "application/did+ld+json", | ||
"retrieved": "2023-03-27T03:52:40Z", | ||
"did": { | ||
"didString": "did:cheqd:testnet:c1685ca0-1f5b-439c-8eb8-5c0e85ab7cd0", | ||
"methodSpecificId": "c1685ca0-1f5b-439c-8eb8-5c0e85ab7cd0", | ||
"method": "cheqd" | ||
} | ||
}, | ||
"contentStream": "eyAKICAgICJjb250ZW50IjogInRlc3QgZGF0YSIKfQ==", | ||
"contentMetadata": { | ||
"resourceURI": "did:cheqd:testnet:c1685ca0-1f5b-439c-8eb8-5c0e85ab7cd0/resources/9ba3922e-d5f5-4f53-b265-fc0d4e988c77", | ||
"resourceCollectionId": "c1685ca0-1f5b-439c-8eb8-5c0e85ab7cd0", | ||
"resourceId": "9ba3922e-d5f5-4f53-b265-fc0d4e988c77", | ||
"resourceName": "Demo Resource", | ||
"resourceType": "String", | ||
"resourceVersion" : "", | ||
"mediaType": "application/json", | ||
"created": "2023-01-25T12:08:39Z", | ||
"checksum": "e1dbc03b50bdb995961dc8843df6539b79d03bf49787ed6462189ee97d27eaf3", | ||
"previousVersionId": null, | ||
"nextVersionId": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.