-
Notifications
You must be signed in to change notification settings - Fork 0
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
f197f53
commit a9a8499
Showing
2 changed files
with
50 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
import 'package:client_sdk_dart/client_sdk_dart.dart'; | ||
import 'dart:html'; | ||
|
||
import 'package:client_sdk_dart/src/auth/credential_provider.dart'; | ||
import 'package:test/test.dart'; | ||
import 'dart:convert'; | ||
|
||
// These tokens have valid syntax, but they don't actually have valid credentials. Just used for unit testing. | ||
var fakeTestLegacyToken = | ||
'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJmb29Abm90LmEuZG9tYWluIiwiY3AiOiJjb250cm9sLXBsYW5lLWVuZHBvaW50Lm5vdC5hLmRvbWFpbiIsImMiOiJjYWNoZS1lbmRwb2ludC5ub3QuYS5kb21haW4ifQo.rtxfu4miBHQ1uptWJ2x3UiAwwJYcMeYIkkpXxUno_wIavg4h6YJStcbxk32NDBbmJkJS7mUw6MsvJNWaxfdPOw'; | ||
var fakeTestV1ApiKey = | ||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NzgzMDU4MTIsImV4cCI6NDg2NTUxNTQxMiwiYXVkIjoiIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSJ9.8Iy8q84Lsr-D3YCo_HP4d-xjHdT8UCIuvAYcxhFMyz8'; | ||
|
||
var decodedV1Token = Base64DecodedV1Token(fakeTestV1ApiKey, "test.momentohq.com"); | ||
var base64EncodedFakeV1AuthToken = base64.encode(utf8.encode(jsonEncode(decodedV1Token))); | ||
var fakeSessionToken = | ||
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InN6eTVJLU5oaDZONjZUbTJfeld2UyJ9.eyJlbWFpbCI6ImNocmlzQG1vbWVudG9ocS5jb20iLCJpc3MiOiJodHRwczovL2xvZ2luLXByZXByb2QuZ29tb21lbnRvLmNvbS8iLCJzdWIiOiJnb29nbGUtb2F1dGgyfDExMDE5OTE5NjYwNDc0NDEwMjQyNSIsImF1ZCI6WyJodHRwczovL3ByZXByb2QiLCJodHRwczovL3ByZXByb2QtbW9tZW50by51cy5hdXRoMC5jb20vdXNlcmluZm8iXSwiaWF0IjoxNjg0Mjg1NDIyLCJleHAiOjE2ODQzNzE4MjIsImF6cCI6InRibFdPYk02Zk9iNkJsQWwzUjFPcWZUNTlrTEY3VGJiIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCJ9.CKJn23XJ9L-seTfOo8OdAbBSP-2DPEM7hvOT1FayojJJvNmyNHzPxcftANlL64lpu5KWIZHwkNaptwkT8v2m7TVeqzDUR52Zqzk7TvQv-FQD_iI4INebPQrCnCKF2ByqC3fdlfrdXBxErF7rOJRKwyugKNhG7WVtjlm9pKOnIIFpUW_0mxWBObrgMhr1qIOaRPoGhyu1TXVgbdn6GLwBDeDI5XbHvgWiMixgs1BpGe_sOOYIcy8l0_TgwQtqUg9GG9Q88Pdde90w_eGLb6bB2QOqXwksBr8zK-z-VZZsiNVdzokKvAvUt3Ev4F1N8Np9ehFbXnzNsTmh1VqkNESy4w'; | ||
|
||
const testControlEndpoint = 'control-plane-endpoint.not.a.domain'; | ||
const testCacheEndpoint = 'cache-endpoint.not.a.domain'; | ||
|
||
void main() { | ||
group('credential_provider', () { | ||
setUp(() { | ||
// Additional setup goes here. | ||
}); | ||
group('fromString', () { | ||
test('parses a valid legacy token', () { | ||
var authProvider = CredentialProvider.fromString(fakeTestLegacyToken); | ||
expect(authProvider.apiKey, equals(fakeTestLegacyToken)); | ||
expect(authProvider.controlEndpoint, equals(testControlEndpoint)); | ||
expect(authProvider.cacheEndpoint, equals(testCacheEndpoint)); | ||
}); | ||
|
||
group("CredentialProvider.fromString", () => { | ||
test('Test reading credentials from a string', () => { | ||
CredentialProvider.fromString("") | ||
}) | ||
test('parses a valid v1 auth token', () { | ||
var authProvider = CredentialProvider.fromString(base64EncodedFakeV1AuthToken); | ||
expect(authProvider.apiKey, equals(fakeTestV1ApiKey)); | ||
expect(authProvider.controlEndpoint, equals('control.${decodedV1Token.endpoint}')); | ||
expect(authProvider.cacheEndpoint, equals('cache.${decodedV1Token.endpoint}')); | ||
}); | ||
}); | ||
}); | ||
} |