Skip to content

Commit 8bc2902

Browse files
DaevMithranAndrew Nikitinabdulla-ashurov
authored
fix: Validation handler to include all resourceMetadata when true (#141)
* fix: Valiation handler to include all resourceMetadata when true * test: Add more unit tests [DEV-2506] (#140) * Add handling for only did queries and small refactoring * Makes linter happy * Add unit tests * Add basic implementation for resource queries * Small refactoring * Add resourceVersion and handler for it * Makes Linter happy * Makes linter happy * Small refactoring * Fix unit tests for queries * MAkes linter happy and fix integration tests * Add more integration tests for queries * Fixed: - added version support - changed logic for allowing versionId and versionTime in the same query - added more integration tests * Changed did doc implementation due to the latest changes in doc * Makes linter happy * Small validation and refactorings * Add checksum handling and small improvements * Fix RequestURI parameter displaying * Makes linter happy * Makes linter happy * Uncomment positive integration tests * Makes linter happy * fix swagger build * Change expected diddoc jsons for integration tests * Add tests for DidDocMetadataList structure * Fix PR review comments * Makes linter happy * Add tests for dereferencing content stream * Add more unit tests * temporary * Add positive cases for resources and diddocs * Fix merging with develop * Fi transformKey tests * Return DIDDocument if metadata=false * Return positive tests back * Add more tests for negative/positive cases * Remove commented imports * Review comments * docs: Reflect DID URL dereferencing changes in swagger (#145) * Actualize swagger docs * Fix golangci-lint mistakes. * Update swagger OpenAPI documentation. --------- Co-authored-by: abdulla-ashurov <[email protected]> * Add tests * Get rid of tests with the same name or resource type. For now, in case of setting resourceMetadata=true it behaves as just filter option. --------- Co-authored-by: Andrew Nikitin <[email protected]> Co-authored-by: abdulla-ashurov <[email protected]>
1 parent 968f0cd commit 8bc2902

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

services/diddoc/queries/resources/resource_validation_handler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ type ResourceValidationHandler struct {
1414
func (d *ResourceValidationHandler) Handle(c services.ResolverContext, service services.RequestServiceI, response types.ResolutionResultI) (types.ResolutionResultI, error) {
1515
resourceName := service.GetQueryParam(types.ResourceName)
1616
resourceType := service.GetQueryParam(types.ResourceType)
17+
resourceMetadata := service.GetQueryParam(types.ResourceMetadata)
1718

1819
// Cast to just list of resources
1920
resourceCollection, err := d.CastToContent(service, response)
2021
if err != nil {
2122
return nil, err
2223
}
2324

25+
if resourceMetadata == "true" {
26+
return d.Continue(c, service, resourceCollection)
27+
}
28+
2429
if resourceType != "" {
2530
// If we have 2 or more resources we need to check resource names.
2631
// If resource names are the same we need to return the latest.

tests/unit/diddoc/request/resource_negative_metadata_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -252,50 +252,4 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t
252252
expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true),
253253
},
254254
),
255-
Entry(
256-
"Negative. There are several resources with the same type but different names",
257-
ResourceMetadataTestCase{
258-
didURL: fmt.Sprintf(
259-
"/1.0/identifiers/%s?resourceType=%s&resourceMetadata=true",
260-
testconstants.ValidDid,
261-
ResourceType1.Metadata.ResourceType,
262-
),
263-
resolutionType: types.DIDJSONLD,
264-
expectedDereferencingResult: &DereferencingResult{
265-
DereferencingMetadata: &types.DereferencingMetadata{
266-
DidProperties: types.DidProperties{
267-
DidString: testconstants.ExistentDid,
268-
MethodSpecificId: testconstants.ValidIdentifier,
269-
Method: testconstants.ValidMethod,
270-
},
271-
},
272-
ContentStream: &types.DereferencedResourceListStruct{},
273-
Metadata: &types.ResolutionDidDocMetadata{},
274-
},
275-
expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true),
276-
},
277-
),
278-
Entry(
279-
"Negative. There are several names with the same name but different types",
280-
ResourceMetadataTestCase{
281-
didURL: fmt.Sprintf(
282-
"/1.0/identifiers/%s?resourceName=%s&resourceMetadata=true",
283-
testconstants.ValidDid,
284-
ResourceType2.Metadata.Name,
285-
),
286-
resolutionType: types.DIDJSONLD,
287-
expectedDereferencingResult: &DereferencingResult{
288-
DereferencingMetadata: &types.DereferencingMetadata{
289-
DidProperties: types.DidProperties{
290-
DidString: testconstants.ExistentDid,
291-
MethodSpecificId: testconstants.ValidIdentifier,
292-
Method: testconstants.ValidMethod,
293-
},
294-
},
295-
ContentStream: &types.DereferencedResourceListStruct{},
296-
Metadata: &types.ResolutionDidDocMetadata{},
297-
},
298-
expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true),
299-
},
300-
),
301255
)

tests/unit/diddoc/request/resources_positive_cases_metadata_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,60 @@ var _ = DescribeTable("Test resource positive cases with Metadata field", func(t
322322
expectedError: nil,
323323
},
324324
),
325+
Entry(
326+
"Positive. Several resources with the same name",
327+
ResourceMetadataTestCase{
328+
didURL: fmt.Sprintf(
329+
"/1.0/identifiers/%s?resourceName=%s&resourceMetadata=true",
330+
testconstants.ValidDid,
331+
ResourceName1.Metadata.Name,
332+
),
333+
resolutionType: types.DIDJSONLD,
334+
expectedDereferencingResult: &DereferencingResult{
335+
DereferencingMetadata: &types.DereferencingMetadata{
336+
DidProperties: types.DidProperties{
337+
DidString: testconstants.ExistentDid,
338+
MethodSpecificId: testconstants.ValidIdentifier,
339+
Method: testconstants.ValidMethod,
340+
},
341+
},
342+
ContentStream: types.NewDereferencedResourceListStruct(
343+
testconstants.ValidDid,
344+
[]*resourceTypes.Metadata{
345+
ResourceName12.Metadata,
346+
ResourceName1.Metadata},
347+
),
348+
Metadata: &types.ResolutionDidDocMetadata{},
349+
},
350+
expectedError: nil,
351+
},
352+
),
353+
Entry(
354+
"Positive. Several resources with the same type",
355+
ResourceMetadataTestCase{
356+
didURL: fmt.Sprintf(
357+
"/1.0/identifiers/%s?resourceType=%s&resourceMetadata=true",
358+
testconstants.ValidDid,
359+
ResourceType1.Metadata.ResourceType,
360+
),
361+
resolutionType: types.DIDJSONLD,
362+
expectedDereferencingResult: &DereferencingResult{
363+
DereferencingMetadata: &types.DereferencingMetadata{
364+
DidProperties: types.DidProperties{
365+
DidString: testconstants.ExistentDid,
366+
MethodSpecificId: testconstants.ValidIdentifier,
367+
Method: testconstants.ValidMethod,
368+
},
369+
},
370+
ContentStream: types.NewDereferencedResourceListStruct(
371+
testconstants.ValidDid,
372+
[]*resourceTypes.Metadata{
373+
ResourceType12.Metadata,
374+
ResourceType1.Metadata,},
375+
),
376+
Metadata: &types.ResolutionDidDocMetadata{},
377+
},
378+
expectedError: nil,
379+
},
380+
),
325381
)

0 commit comments

Comments
 (0)