Skip to content

Commit

Permalink
fix: Add enroll param values to notification value and update the fun…
Browse files Browse the repository at this point in the history
…ctional test to verify new fields in the notification value
  • Loading branch information
sitaram-kalluri committed Feb 26, 2024
1 parent f667660 commit f0db09f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ class EnrollVerbHandler extends AbstractVerbHandler {
var notificationValue = {};
notificationValue[AtConstants.apkamEncryptedSymmetricKey] =
enrollParams.encryptedAPKAMSymmetricKey;
notificationValue[AtConstants.appName] = enrollParams.appName;
notificationValue[AtConstants.deviceName] = enrollParams.deviceName;
notificationValue[AtConstants.namespace] = enrollParams.namespaces;
logger.finer('notificationValue:$notificationValue');
final atNotification = (AtNotificationBuilder()
..notification = key
Expand Down
31 changes: 20 additions & 11 deletions tests/at_functional_test/test/enroll_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ void main() {
at_demos.encryptionPrivateKeyMap[firstAtSign]!,
at_demos.apkamSymmetricKeyMap[firstAtSign]!),
'encryptedSelfEncKey': EncryptionUtil.encryptValue(
at_demos.aesKeyMap[firstAtSign]!,
at_demos.apkamSymmetricKeyMap[firstAtSign]!),
'encryptedApkamSymmetricKey': EncryptionUtil.encryptValue(
at_demos.aesKeyMap[firstAtSign]!,
at_demos.apkamSymmetricKeyMap[firstAtSign]!)
};
Expand All @@ -44,7 +47,7 @@ void main() {
authType: AuthType.cram);
// send an enroll request with the keys from the setEncryptionKeys method
String enrollRequest =
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptedPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}"}\n';
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptionPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}"}\n';
String enrollResponse =
(await firstAtSignConnection.sendRequestToServer(enrollRequest))
.replaceAll('data:', '');
Expand Down Expand Up @@ -148,7 +151,7 @@ void main() {
authType: AuthType.cram);
// send an enroll request with the keys from the setEncryptionKeys method
var enrollRequest =
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptedPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}"}';
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptionPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}"}';
String enrollResponse =
await firstAtSignConnection.sendRequestToServer(enrollRequest);
enrollResponse = enrollResponse.replaceFirst('data:', '');
Expand Down Expand Up @@ -295,7 +298,7 @@ void main() {
await firstAtSignConnection.authenticateConnection(
authType: AuthType.cram);
var enrollRequest =
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptedPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}"}';
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptionPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}"}';
String enrollResponse =
(await firstAtSignConnection.sendRequestToServer(enrollRequest))
.replaceFirst('data:', '');
Expand All @@ -313,7 +316,7 @@ void main() {
firstAtSign, firstAtSignHost, firstAtSignPort);
//send second enroll request with otp
String secondEnrollRequest =
'enroll:request:{"appName":"buzz","deviceName":"pixel","namespaces":{"buzz":"rw"},"otp":"$otpResponse","encryptedDefaultEncryptedPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${apkamPublicKeyMap[firstAtSign]!}"}';
'enroll:request:{"appName":"buzz","deviceName":"pixel","namespaces":{"buzz":"rw"},"otp":"$otpResponse","encryptedDefaultEncryptionPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${apkamPublicKeyMap[firstAtSign]!}"}';
String secondEnrollResponse =
(await socketConnection2.sendRequestToServer(secondEnrollRequest))
.replaceFirst('data:', '');
Expand Down Expand Up @@ -362,13 +365,13 @@ void main() {
await firstAtSignConnection.sendRequestToServer('otp:get');
otpResponse = otpResponse.replaceFirst('data:', '');
otpResponse = otpResponse.trim();
firstAtSignConnection.close();
await firstAtSignConnection.close();
// Connect to unauthenticated socket to send an enrollment request
firstAtSignConnection = await OutboundConnectionFactory()
.initiateConnectionWithListener(
firstAtSign, firstAtSignHost, firstAtSignPort);
var secondEnrollRequest =
'enroll:request:{"appName":"buzz","deviceName":"pixel","namespaces":{"buzz":"rw"},"otp":"$otpResponse","encryptedDefaultEncryptedPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${apkamPublicKeyMap[firstAtSign]!}"}';
'enroll:request:{"appName":"buzz","deviceName":"pixel","namespaces":{"buzz":"rw"},"otp":"$otpResponse","encryptedDefaultEncryptionPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${apkamPublicKeyMap[firstAtSign]!}","encryptedAPKAMSymmetricKey":"${apkamEncryptedKeysMap['encryptedApkamSymmetricKey']}"}';
var secondEnrollResponse =
await firstAtSignConnection.sendRequestToServer(secondEnrollRequest);
secondEnrollResponse = secondEnrollResponse.replaceFirst('data:', '');
Expand Down Expand Up @@ -400,6 +403,11 @@ void main() {
serverResponse.contains(
'${enrollJson['enrollmentId']}.new.enrollments.__manage'),
true);
Map notificationValue = jsonDecode(jsonDecode(serverResponse.replaceAll('notification: ',''))['value']);
expect(notificationValue['appName'], 'buzz');
expect(notificationValue['deviceName'], 'pixel');
expect(notificationValue['namespace'], {'buzz':'rw'});
expect(notificationValue['encryptedApkamSymmetricKey'], apkamEncryptedKeysMap['encryptedApkamSymmetricKey']);
monitorSocket.close();
}
/* Setting count to 4 to wait until server returns 4 responses
Expand All @@ -417,7 +425,7 @@ void main() {
authType: AuthType.cram);
// send an enroll request with the keys from the setEncryptionKeys method
String enrollRequest =
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptedPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}"}';
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptionPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}"}';
String enrollResponse =
(await firstAtSignConnection.sendRequestToServer(enrollRequest))
.replaceFirst('data:', '');
Expand Down Expand Up @@ -474,7 +482,7 @@ void main() {
await firstAtSignConnection.authenticateConnection(
authType: AuthType.cram);
String enrollRequest =
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}"}';
'enroll:request:{"appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"apkamPublicKey":"${apkamPublicKeyMap[firstAtSign]!}"}';
String enrollmentResponse =
await firstAtSignConnection.sendRequestToServer(enrollRequest);
String enrollmentId = jsonDecode(
Expand All @@ -484,9 +492,10 @@ void main() {
OutboundConnectionFactory socketConnection2 =
await OutboundConnectionFactory().initiateConnectionWithListener(
firstAtSign, firstAtSignHost, firstAtSignPort);
socketConnection2.authenticateConnection(
String authResponse = await socketConnection2.authenticateConnection(
authType: AuthType.apkam, enrollmentId: enrollmentId);
socketConnection2.close();
expect(authResponse.trim(), 'data:success');
await socketConnection2.close();

// Revoke the enrollment
String revokeEnrollmentCommand =
Expand Down Expand Up @@ -524,7 +533,7 @@ void main() {
await OutboundConnectionFactory().initiateConnectionWithListener(
firstAtSign, firstAtSignHost, firstAtSignPort);
String revokeEnrollmentCommand =
'enroll:revoke:enrollmentid:$enrollmentId';
'enroll:revoke:{"enrollmentid":"$enrollmentId"}';
String revokeEnrollmentResponse = await socketConnection2
.sendRequestToServer(revokeEnrollmentCommand);
expect(revokeEnrollmentResponse.trim(),
Expand Down

0 comments on commit f0db09f

Please sign in to comment.