-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add unit tests for update verb builder isEncrypted
- Loading branch information
1 parent
4affdfd
commit 141716a
Showing
1 changed file
with
75 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -523,4 +523,79 @@ void main() { | |
}); | ||
}); | ||
}); | ||
group('A group of tests to validate isEncrypted flag in update verb builder', | ||
() { | ||
test('for public key isEncrypted is false', () { | ||
var updateBuilder = UpdateVerbBuilder() | ||
..value = '[email protected]' | ||
..atKey.metadata.isPublic = true | ||
..atKey.metadata.ttl = 5000 | ||
..atKey.key = 'email' | ||
..atKey.sharedBy = '@alice'; | ||
var updateCommand = updateBuilder.buildCommand(); | ||
expect(updateCommand, | ||
'update:ttl:5000:public:email@alice [email protected]\n'); | ||
var updateVerbParams = | ||
getVerbParams(VerbSyntax.update, updateCommand.trim()); | ||
print(updateVerbParams); | ||
// existing behaviour. TODO change to false after changes for update verb isEncrypted flag | ||
expect(updateVerbParams['isEncrypted'], null); | ||
}); | ||
test('for shared key - isEncrypted is true if set in metadata', () { | ||
var updateBuilder = UpdateVerbBuilder() | ||
..value = 'sampleEncryptedValue' | ||
..atKey.metadata.ttl = 5000 | ||
..atKey.metadata.isEncrypted = true | ||
..atKey.key = 'email' | ||
..atKey.sharedBy = '@alice' | ||
..atKey.sharedWith = '@bob'; | ||
var updateCommand = updateBuilder.buildCommand(); | ||
print(updateCommand); | ||
expect(updateCommand, | ||
'update:ttl:5000:isEncrypted:true:@bob:email@alice sampleEncryptedValue\n'); | ||
var updateVerbParams = | ||
getVerbParams(VerbSyntax.update, updateCommand.trim()); | ||
print(updateVerbParams); | ||
expect(updateVerbParams['isEncrypted'], 'true'); | ||
}); | ||
test('for shared key - isEncrypted is false if NOT set in metadata', () { | ||
var updateBuilder = UpdateVerbBuilder() | ||
..value = 'sampleEncryptedValue' | ||
..atKey.metadata.ttl = 5000 | ||
..atKey.key = 'email' | ||
..atKey.sharedBy = '@alice' | ||
..atKey.sharedWith = '@bob'; | ||
var updateCommand = updateBuilder.buildCommand(); | ||
print(updateCommand); | ||
// existing behaviour. TODO Should contain isEncrypted:false after changes for update verb isEncrypted flag | ||
expect(updateCommand, | ||
'update:ttl:5000:@bob:email@alice sampleEncryptedValue\n'); | ||
var updateVerbParams = | ||
getVerbParams(VerbSyntax.update, updateCommand.trim()); | ||
print(updateVerbParams); | ||
// existing behaviour. TODO Should be false after changes for update verb isEncrypted flag | ||
expect(updateVerbParams['isEncrypted'], null); | ||
}); | ||
|
||
test('for shared key - isEncrypted is false if set to false in metadata', | ||
() { | ||
var updateBuilder = UpdateVerbBuilder() | ||
..value = 'sampleEncryptedValue' | ||
..atKey.metadata.ttl = 5000 | ||
..atKey.metadata.isEncrypted = false | ||
..atKey.key = 'email' | ||
..atKey.sharedBy = '@alice' | ||
..atKey.sharedWith = '@bob'; | ||
var updateCommand = updateBuilder.buildCommand(); | ||
print(updateCommand); | ||
// existing behaviour. TODO Should contain isEncrypted:false after changes for update verb isEncrypted flag | ||
expect(updateCommand, | ||
'update:ttl:5000:@bob:email@alice sampleEncryptedValue\n'); | ||
var updateVerbParams = | ||
getVerbParams(VerbSyntax.update, updateCommand.trim()); | ||
print(updateVerbParams); | ||
// existing behaviour. TODO Should be false after changes for update verb isEncrypted flag | ||
expect(updateVerbParams['isEncrypted'], null); | ||
}); | ||
}); | ||
} |