-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rename to didcore and fix failing http tests
- Loading branch information
1 parent
e4c1dd7
commit ef84ad0
Showing
21 changed files
with
228 additions
and
36 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 was deleted.
Oops, something went wrong.
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,11 @@ | ||
export 'did_core/did_service.dart'; | ||
export 'did_core/did_resource.dart'; | ||
export 'did_core/did_document.dart'; | ||
export 'did_core/did_resolution_result.dart'; | ||
export 'did_core/did_dereference_result.dart'; | ||
export 'did_core/did_verification_method.dart'; | ||
export 'did_core/did_resolution_metadata.dart'; | ||
export 'did_core/did_dereference_options.dart'; | ||
export 'did_core/did_dereference_metadata.dart'; | ||
export 'did_core/did_document_metadata.dart'; | ||
export 'did_core/did_verification_relationship.dart'; |
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...ds/structures/did_dereference_result.dart → ...dids/did_core/did_dereference_result.dart
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
8 changes: 4 additions & 4 deletions
8
...lib/src/dids/structures/did_document.dart → ...5/lib/src/dids/did_core/did_document.dart
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
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../lib/src/dids/structures/did_service.dart → ...b5/lib/src/dids/did_core/did_service.dart
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
2 changes: 1 addition & 1 deletion
2
...s/structures/did_verification_method.dart → ...ids/did_core/did_verification_method.dart
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
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ dependencies: | |
|
||
dev_dependencies: | ||
lints: ^3.0.0 | ||
mocktail: ^1.0.3 | ||
test: ^1.21.0 |
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 |
---|---|---|
@@ -1,20 +1,148 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:web5/src/dids/did_core/did_resolution_result.dart'; | ||
import 'package:web5/src/dids/did_web/did_web.dart'; | ||
|
||
class MockHttpClient extends Mock implements HttpClient {} | ||
|
||
class MockHttpRequest extends Mock implements HttpClientRequest {} | ||
|
||
class MockHttpResponse extends Mock implements HttpClientResponse {} | ||
|
||
const validDidWebDocument = '''{ | ||
"id": "did:web:www.linkedin.com", | ||
"@context": [ | ||
"https://www.w3.org/ns/did/v1", | ||
{ | ||
"@base": "did:web:www.linkedin.com" | ||
} | ||
], | ||
"service": [ | ||
{ | ||
"id": "#linkeddomains", | ||
"type": "LinkedDomains", | ||
"serviceEndpoint": { | ||
"origins": [ | ||
"https://www.linkedin.com/" | ||
] | ||
} | ||
}, | ||
{ | ||
"id": "#hub", | ||
"type": "IdentityHub", | ||
"serviceEndpoint": { | ||
"instances": [ | ||
"https://hub.did.msidentity.com/v1.0/658728e7-1632-412a-9815-fe53f53ec58b" | ||
] | ||
} | ||
} | ||
], | ||
"verificationMethod": [ | ||
{ | ||
"id": "#074cfbf193f046bcba5841ac4751e91bvcSigningKey-46682", | ||
"controller": "did:web:www.linkedin.com", | ||
"type": "EcdsaSecp256k1VerificationKey2019", | ||
"publicKeyJwk": { | ||
"crv": "secp256k1", | ||
"kty": "EC", | ||
"x": "NHIQivVR0HX7c0flpxgWQ7vRtbWDvr0UPN1nJ--0lyU", | ||
"y": "hYiIldgLRShym7vzflFrEkg6NYkayUHkDpV0RMjUEYE" | ||
} | ||
} | ||
], | ||
"authentication": [ | ||
"#074cfbf193f046bcba5841ac4751e91bvcSigningKey-46682" | ||
], | ||
"assertionMethod": [ | ||
"#074cfbf193f046bcba5841ac4751e91bvcSigningKey-46682" | ||
] | ||
}'''; | ||
|
||
void main() { | ||
final MockHttpClient mockClient = MockHttpClient(); | ||
final MockHttpRequest request = MockHttpRequest(); | ||
final MockHttpResponse response = MockHttpResponse(); | ||
|
||
setUpAll(() { | ||
registerFallbackValue(Uri()); | ||
}); | ||
|
||
setUp(() { | ||
reset(mockClient); | ||
reset(request); | ||
reset(response); | ||
}); | ||
|
||
group('DidWeb', () { | ||
test('should return invalid did with bad data', () async { | ||
final result = await DidWeb.resolve('bogus'); | ||
expect(result, DidResolutionResult.invalidDid()); | ||
}); | ||
|
||
test('should return invalid did with wrong method', () async { | ||
final result = await DidWeb.resolve('did:bad:www.linkedin.com'); | ||
expect(result, DidResolutionResult.invalidDid()); | ||
}); | ||
|
||
test('should return invalid did with failed http request', () async { | ||
when(() => response.statusCode).thenReturn(400); | ||
when(() => request.close()).thenAnswer((_) async => response); | ||
when(() => mockClient.getUrl(any())).thenAnswer((_) async => request); | ||
|
||
final result = await DidWeb.resolve( | ||
'did:web:www.linkedin.com', | ||
client: mockClient, | ||
); | ||
expect(result, DidResolutionResult.invalidDid()); | ||
}); | ||
|
||
test('should resolve successfully', () async { | ||
final result = await DidWeb.resolve('did:web:www.linkedin.com'); | ||
expect(result.didDocument, isNotNull); | ||
when(() => response.statusCode).thenReturn(200); | ||
when(() => response.transform(utf8.decoder)) | ||
.thenAnswer((_) => Stream.value(validDidWebDocument)); | ||
when(() => request.close()).thenAnswer((_) async => response); | ||
when( | ||
() => mockClient.getUrl( | ||
Uri.parse('https://www.linkedin.com/.well-known/did.json'), | ||
), | ||
).thenAnswer((_) async => request); | ||
|
||
final result = | ||
await DidWeb.resolve('did:web:www.linkedin.com', client: mockClient); | ||
|
||
expect(result.didDocument, isNotNull); | ||
expect('did:web:www.linkedin.com', result.didDocument!.id); | ||
|
||
verify( | ||
() => mockClient | ||
.getUrl(Uri.parse('https://www.linkedin.com/.well-known/did.json')), | ||
); | ||
}); | ||
|
||
test('should resolve with paths', () async { | ||
final result = await DidWeb.resolve('did:web:localhost%3A8892:ingress'); | ||
test('should resolve successfully with paths', () async { | ||
when(() => response.statusCode).thenReturn(200); | ||
when(() => response.transform(utf8.decoder)) | ||
.thenAnswer((_) => Stream.value(validDidWebDocument)); | ||
when(() => request.close()).thenAnswer((_) async => response); | ||
when( | ||
() => mockClient.getUrl( | ||
Uri.parse('http://localhost:8892/ingress/did.json'), | ||
), | ||
).thenAnswer((_) async => request); | ||
|
||
final result = await DidWeb.resolve( | ||
'did:web:localhost%3A8892:ingress', | ||
client: mockClient, | ||
); | ||
expect(result.didDocument, isNotNull); | ||
|
||
expect('did:web:localhost%3A8892:ingress', result.didDocument!.id); | ||
verify( | ||
() => mockClient | ||
.getUrl(Uri.parse('http://localhost:8892/ingress/did.json')), | ||
); | ||
}); | ||
}); | ||
} |