-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathconfig_verifier_test.dart
More file actions
145 lines (129 loc) · 4.67 KB
/
config_verifier_test.dart
File metadata and controls
145 lines (129 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:freerasp/freerasp.dart';
import 'package:freerasp/src/utils/config_verifier.dart';
void main() {
group('Verify Android config', () {
test('Should return normally when valid parameters provided', () {
// Arrange
const validHash = 'AKoRuyLMM91E7lX/Zqp3u4jMmd0A7hH/Iqozu0TMVd0=';
final config = AndroidConfig(
packageName: 'packageName',
signingCertHashes: [validHash],
);
// Act & Assert
expect(() => ConfigVerifier.verifyAndroid(config), returnsNormally);
});
test('Should throw $ConfigurationException when invalid hash format', () {
// Arrange
const invalidHash = 'invalidHash';
// Act & Assert
expect(
() => AndroidConfig(
packageName: 'packageName',
signingCertHashes: [invalidHash],
),
throwsA(isA<ConfigurationException>()),
);
});
test(
'Should throw $ConfigurationException when one of hashes has invalid '
'format', () {
// Arrange
const validHash = 'AKoRuyLMM91E7lX/Zqp3u4jMmd0A7hH/Iqozu0TMVd0=';
const invalidHash = 'invalidHash';
// Act & Assert
expect(
() => AndroidConfig(
packageName: 'packageName',
signingCertHashes: [validHash, invalidHash],
),
throwsA(isA<ConfigurationException>()),
);
});
test('Should throw $ConfigurationException when cert hashes are empty', () {
expect(
() => AndroidConfig(
packageName: 'packageName',
signingCertHashes: [],
),
throwsA(isA<ConfigurationException>()),
);
});
test('Should throw $ConfigurationException when package name is empty', () {
// Arrange
const validHash = 'AKoRuyLMM91E7lX/Zqp3u4jMmd0A7hH/Iqozu0TMVd0=';
// Act & Assert
expect(
() => AndroidConfig(
packageName: '',
signingCertHashes: [validHash],
),
throwsA(isA<ConfigurationException>()),
);
});
test('Should encode TalsecConfig to String', () {
// Arrange
const expectedString =
'{"androidConfig":{"packageName":"com.aheaditec.freeraspExample","signingCertHashes":["AKoRuyLMM91E7lX/Zqp3u4jMmd0A7hH/Iqozu0TMVd0="],"supportedStores":["com.sec.android.app.samsungapps"]},"iosConfig":{"bundleIds":["com.aheaditec.freeraspExample"],"teamId":"M8AK35..."},"watcherMail":"test_mail@example.com","isProd":false,"killOnBypass":true}';
final config = TalsecConfig(
androidConfig: AndroidConfig(
packageName: 'com.aheaditec.freeraspExample',
signingCertHashes: ['AKoRuyLMM91E7lX/Zqp3u4jMmd0A7hH/Iqozu0TMVd0='],
supportedStores: ['com.sec.android.app.samsungapps'],
),
iosConfig: IOSConfig(
bundleIds: ['com.aheaditec.freeraspExample'],
teamId: 'M8AK35...',
),
watcherMail: 'test_mail@example.com',
isProd: false,
killOnBypass: true,
);
// Act & Assert
expect(
jsonEncode(config.toJson()),
equals(expectedString),
);
});
test('Should decode String to TalsecConfig', () {
// Arrange
final expectedConfig = TalsecConfig(
androidConfig: AndroidConfig(
packageName: 'com.aheaditec.freeraspExample',
signingCertHashes: ['AKoRuyLMM91E7lX/Zqp3u4jMmd0A7hH/Iqozu0TMVd0='],
supportedStores: ['com.sec.android.app.samsungapps'],
),
iosConfig: IOSConfig(
bundleIds: ['com.aheaditec.freeraspExample'],
teamId: 'M8AK35...',
),
watcherMail: 'test_mail@example.com',
isProd: false,
killOnBypass: true,
);
const config =
'{"androidConfig":{"packageName":"com.aheaditec.freeraspExample","signingCertHashes":["AKoRuyLMM91E7lX/Zqp3u4jMmd0A7hH/Iqozu0TMVd0="],"supportedStores":["com.sec.android.app.samsungapps"]},"iosConfig":{"bundleIds":["com.aheaditec.freeraspExample"],"teamId":"M8AK35..."},"watcherMail":"test_mail@example.com","isProd":false,"killOnBypass":true}';
// Act
final actualConfig =
TalsecConfig.fromJson(jsonDecode(config) as Map<String, dynamic>);
// Assert
expect(
actualConfig.watcherMail,
equals(expectedConfig.watcherMail),
);
expect(
actualConfig.isProd,
equals(expectedConfig.isProd),
);
expect(
actualConfig.androidConfig?.signingCertHashes,
equals(expectedConfig.androidConfig?.signingCertHashes),
);
expect(
actualConfig.iosConfig?.bundleIds,
equals(expectedConfig.iosConfig?.bundleIds),
);
});
});
}