-
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.
Merge pull request #14 from momentohq/chore/unitTestCredProvider
chore: add unit test for cred provider
- Loading branch information
Showing
5 changed files
with
94 additions
and
26 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// // TODO: Put public facing types in this file. | ||
// | ||
// import '../generated/cachepubsub.pb.dart'; | ||
// import 'package:grpc/grpc.dart'; | ||
// | ||
// abstract class ITopicClient { | ||
// void publish(); | ||
// } | ||
// | ||
// class TopicClient implements ITopicClient { | ||
// ClientChannel _channel; | ||
// | ||
// TopicClient() { | ||
// _channel = ClientChannel(host) | ||
// } | ||
// @override | ||
// void publish() { | ||
// // TODO: implement publish | ||
// } | ||
// | ||
// void close() { | ||
// | ||
// } | ||
// } | ||
// | ||
// /// Checks if you are awesome. Spoiler: you are. | ||
// class Awesome { | ||
// bool get isAwesome => true; | ||
// } | ||
// | ||
// PubsubApi api = PubsubApi(); |
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,42 @@ | ||
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', () { | ||
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)); | ||
}); | ||
|
||
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}')); | ||
}); | ||
}); | ||
}); | ||
} |