-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest-api-location-verification.html
263 lines (227 loc) · 8.96 KB
/
test-api-location-verification.html
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/mocha.min.css">
<title>Tests</title>
</head>
<body>
<pre>
Background:
Given the API root is "http://localhost:9091"
And the base path is "location-verification/v0"
Scenario: Execute location verification for a user equipment
Given a device with the following details:
| phoneNumber | 123456789 |
| networkAccessIdentifier| [email protected] |
| ipv4Address.publicAddress | 84.125.93.10 |
| ipv4Address.publicPort | 59765 |
And a circular area with the following details:
| type | Circle |
| location.latitude | 50.735851 |
| location.longitude | 7.10066 |
| accuracy | 50 |
When I execute the location verification request
Then the response should have a verification result of "TRUE"
Scenario: Execute location verification for a user equipment partially
Given a device with the following details:
| phoneNumber | 123456789 |
| networkAccessIdentifier| [email protected] |
| ipv4Address.publicAddress | 84.125.93.10 |
</pre>
<div id="mocha"></div>
</body>
</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/10.2.0/mocha.min.js"
integrity="sha512-jsP/sG70bnt0xNVJt+k9NxQqGYvRrLzWhI+46SSf7oNJeCwdzZlBvoyrAN0zhtVyolGcHNh/9fEgZppG2pH+eA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/chai.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
mocha.setup("bdd");
mocha.timeout(20000);
const expect = chai.expect;
const version = '0.3.1'; // supported spec version
// set up values
const apiRoot = 'http://localhost:9091';
const basePath = 'location-verification/v0';
const baseURL = `${apiRoot}/${basePath}`;
let token = "";
const device = {
phoneNumber: '123456789',
networkAccessIdentifier: '[email protected]',
ipv4Address: {
publicAddress: '84.125.93.10',
publicPort: 59765
}
};
const area = {
type: 'Circle',
location: {
latitude: 50.735851,
longitude: 7.10066
},
accuracy: 50
};
const expectedResponse = {
verificationResult: 'TRUE',
};
const device2 = {
phoneNumber: '123456789'
};
const expectedResponse2 = {
verificationResult: 'PARTIAL',
matchRate: 74,
};
const area3 = {
type: 'Circle',
location: {
latitude: 50.735851,
longitude: 7.10066
},
accuracy: -10 // Invalid accuracy
};
const expectedResponse3 = {
status: 400,
code: 'INVALID_ARGUMENT',
message: 'Invalid input',
};
// Test Suite
describe("Device location verification API Tests", function () {
// Authentication test case
describe('Authentication Tests', function () {
it('should include OAuth2 client credentials security', async () => {
// TODO: Write the test case to verify OAuth2 client credentials security
});
it('should include three-legged OAuth2 security with location-verification-read scope',
async () => {
// TODO: Write the test case to verify three-legged OAuth2 security with location-verification-read scope
});
it("Successful Authentication should return a token", async function () {
let response = await axios.post(`${baseURL}/authenticate`, {
username: 'test-user',
password: 'test-pass'
});
expect(response.status).to.equal(200);
token = response.data.token;
expect(token).to.be.a('string');
});
});
// Authorization test case
describe('Authorization Tests', function () {
// TODO: Write test cases to verify authorization for different user roles and permissions
it("TODO: Write test cases to verify authorization for different user roles and permissions ",
function () {
expect("0").to.equal("1");
});
it("Unauthorized request should return 401", async function () {
try {
let response = await axios.post(`${baseURL}/verifications`);
} catch (error) {
expect(error.response.status).to.equal(401);
}
});
it("Authorized request should return 200", async function () {
let response = await axios.post(`${baseURL}/verifications`, {
device: 'device1',
area: 'area1'
}, {
headers: {
Authorization: `Bearer ${token}`
}
});
expect(response.status).to.equal(200);
});
});
// Security test case
describe('Security Tests', function () {
//TODO: Write test cases to verify security measures such as encryption, input validation, etc.
it("TODO: Write test cases to verify security measures such as encryption, input validation, etc.",
function () {
expect("0").to.equal("1");
});
it("Invalid token should return 403", async function () {
try {
let response = await axios.post(`${baseURL}/verifications`, {
device: 'device1',
area: 'area1'
}, {
headers: {
Authorization: `Bearer ${'invalidToken'}`
}
});
} catch (error) {
expect(error.response.status).to.equal(403);
}
});
it("No token should return 401", async function () {
try {
let response = await axios.post(`${baseURL}/verifications`, {
device: 'device1',
area: 'area1'
});
} catch (error) {
expect(error.response.status).to.equal(401);
}
});
});
// Tests for specific URI like /verifications
describe('Location Verification', function () {
it("Successful verification should return 200", async function () {
let response = await axios.post(`${baseURL}/verifications`, {
device: device,
area: area
}, {
headers: {
Authorization: `Bearer ${token}`
}
});
expect(response.status).to.equal(200);
expect(response.data.verificationResult).to.be.a('string');
});
it("Invalid device should return 404", async function () {
try {
let response = await axios.post(`${baseURL}/verifications`, {
device: 'invalidDevice',
area: area
}, {
headers: {
Authorization: `Bearer ${token}`
}
});
} catch (error) {
expect(error.response.status).to.equal(404);
}
});
it("Missing device parameters should return 400", async function () {
try {
let response = await axios.post(`${baseURL}/verifications`, {
area: area
}, {
headers: {
Authorization: `Bearer ${token}`
}
});
} catch (error) {
expect(error.response.status).to.equal(400);
}
});
it("Missing area parameters should return 400", async function () {
try {
let response = await axios.post(`${baseURL}/verifications`, {
device: device
}, {
headers: {
Authorization: `Bearer ${token}`
}
});
} catch (error) {
expect(error.response.status).to.equal(400);
}
});
});
});
mocha.run();
</script>