gdpr-api-tester 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gdpr-api-tester-0.0.1/LICENSE +21 -0
- gdpr-api-tester-0.0.1/MANIFEST.in +1 -0
- gdpr-api-tester-0.0.1/PKG-INFO +357 -0
- gdpr-api-tester-0.0.1/README.md +294 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester/__init__.py +0 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester/__main__.py +5 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester/config.py +83 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester/main.py +365 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester/routes.py +50 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester/rsa_key.py +55 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester.egg-info/PKG-INFO +357 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester.egg-info/SOURCES.txt +17 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester.egg-info/dependency_links.txt +1 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester.egg-info/entry_points.txt +2 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester.egg-info/requires.txt +24 -0
- gdpr-api-tester-0.0.1/gdpr_api_tester.egg-info/top_level.txt +3 -0
- gdpr-api-tester-0.0.1/pyproject.toml +36 -0
- gdpr-api-tester-0.0.1/requirements.txt +66 -0
- gdpr-api-tester-0.0.1/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 City of Helsinki
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include requirements.txt
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: gdpr-api-tester
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Helsinki Profile GDPR API Tester
|
|
5
|
+
Author-email: Mikko Keskinen <mikko.keskinen@hel.fi>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2023 City of Helsinki
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/City-of-Helsinki/profile-gdpr-api-tester
|
|
29
|
+
Project-URL: Bug Tracker, https://github.com/City-of-Helsinki/profile-gdpr-api-tester/issues
|
|
30
|
+
Classifier: Intended Audience :: Developers
|
|
31
|
+
Classifier: Environment :: Console
|
|
32
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
33
|
+
Classifier: Operating System :: OS Independent
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
36
|
+
Requires-Python: >=3.10
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
License-File: LICENSE
|
|
39
|
+
Requires-Dist: aioconsole==0.5.1
|
|
40
|
+
Requires-Dist: aiohttp==3.8.3
|
|
41
|
+
Requires-Dist: aiosignal==1.3.1
|
|
42
|
+
Requires-Dist: async-timeout==4.0.2
|
|
43
|
+
Requires-Dist: attrs==22.2.0
|
|
44
|
+
Requires-Dist: build==0.9.0
|
|
45
|
+
Requires-Dist: charset-normalizer==2.1.1
|
|
46
|
+
Requires-Dist: click==8.1.3
|
|
47
|
+
Requires-Dist: colorama==0.4.6
|
|
48
|
+
Requires-Dist: ecdsa==0.18.0
|
|
49
|
+
Requires-Dist: frozenlist==1.3.3
|
|
50
|
+
Requires-Dist: idna==3.4
|
|
51
|
+
Requires-Dist: multidict==6.0.4
|
|
52
|
+
Requires-Dist: packaging==22.0
|
|
53
|
+
Requires-Dist: pep517==0.13.0
|
|
54
|
+
Requires-Dist: pip-tools==6.12.1
|
|
55
|
+
Requires-Dist: pyasn1==0.4.8
|
|
56
|
+
Requires-Dist: python-dotenv==0.21.0
|
|
57
|
+
Requires-Dist: python-jose==3.3.0
|
|
58
|
+
Requires-Dist: rsa==4.9
|
|
59
|
+
Requires-Dist: six==1.16.0
|
|
60
|
+
Requires-Dist: tomli==2.0.1
|
|
61
|
+
Requires-Dist: wheel==0.38.4
|
|
62
|
+
Requires-Dist: yarl==1.8.2
|
|
63
|
+
|
|
64
|
+
Helsinki Profile GDPR API Tester
|
|
65
|
+
================================
|
|
66
|
+
|
|
67
|
+
Profile GDPR API Tester is a command line tool for testing GDPR API implementations that conform to the Helsinki Profile GDPR API specification.
|
|
68
|
+
This tools main usage is to test the API Token authentication in the implemented GDPR API.
|
|
69
|
+
|
|
70
|
+
See [GDPR API Description](https://helsinkisolutionoffice.atlassian.net/wiki/spaces/KAN/pages/80969736/GDPR+API+Description) for more information about the GDPR API.
|
|
71
|
+
|
|
72
|
+
# Requirements
|
|
73
|
+
|
|
74
|
+
Python 3.10+ or Docker
|
|
75
|
+
|
|
76
|
+
# Installing / Running
|
|
77
|
+
|
|
78
|
+
## Running from a GitHub package using Docker
|
|
79
|
+
|
|
80
|
+
Copy [env.example](env.example) to your local filesystem as `.env` and change the settings to suit your environment. (See [configuration](#configuration))
|
|
81
|
+
|
|
82
|
+
```shell
|
|
83
|
+
docker run -i -p 8888:8888 --env-file .env ghcr.io/city-of-helsinki/profile-gdpr-api-tester
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## Installing using pip
|
|
88
|
+
|
|
89
|
+
You can install this tool in your local Python environment by running
|
|
90
|
+
|
|
91
|
+
```shell
|
|
92
|
+
pip install gdpr-api-tester
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Running after installing with pip
|
|
96
|
+
|
|
97
|
+
Copy [env.example](env.example) to `.env` and change the settings to suit your environment. (See [configuration](#configuration))
|
|
98
|
+
|
|
99
|
+
Then run the command:
|
|
100
|
+
|
|
101
|
+
```shell
|
|
102
|
+
gdpr_api_tester
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Building and running using Docker
|
|
106
|
+
|
|
107
|
+
Clone this repository
|
|
108
|
+
|
|
109
|
+
```shell
|
|
110
|
+
git clone https://github.com/City-of-Helsinki/profile-gdpr-api-tester
|
|
111
|
+
cd profile-gdpr-api-tester
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Copy [env.example](env.example) to `.env` and change the settings to suit your environment. (See [configuration](#configuration))
|
|
115
|
+
|
|
116
|
+
```shell
|
|
117
|
+
cp env.example .env
|
|
118
|
+
$EDITOR .env
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Then build and run a Docker image:
|
|
122
|
+
|
|
123
|
+
```shell
|
|
124
|
+
docker build -t gdpr-api-tester .
|
|
125
|
+
docker run -i -p 8888:8888 --env-file .env gdpr-api-tester
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
## Running from this repo
|
|
130
|
+
|
|
131
|
+
```shell
|
|
132
|
+
git clone https://github.com/City-of-Helsinki/profile-gdpr-api-tester
|
|
133
|
+
cd profile-gdpr-api-tester
|
|
134
|
+
cp env.example .env
|
|
135
|
+
python -m venv venv
|
|
136
|
+
source venv/bin/activate
|
|
137
|
+
pip install -r requirements.txt
|
|
138
|
+
python -m gdpr_api_tester
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
# Configuration
|
|
142
|
+
|
|
143
|
+
The tool reads configuration from environment variables and from a file named `.env`. There is an example env file ([env.example](env.example)) in the repository. You can use it as a base for your own configuration.
|
|
144
|
+
|
|
145
|
+
Following is a list of all the configuration options:
|
|
146
|
+
|
|
147
|
+
### ISSUER
|
|
148
|
+
|
|
149
|
+
The issuer in the generated API tokens and the address of the GDPR API Tester. The API must have connectivity to this address because the JWT token verification will fetch the public key from here.
|
|
150
|
+
|
|
151
|
+
### GDPR_API_AUDIENCE
|
|
152
|
+
|
|
153
|
+
The audience in the generated API tokens. i.e. The client id of the GDPR API.
|
|
154
|
+
|
|
155
|
+
### GDPR_API_AUTHORIZATION_FIELD
|
|
156
|
+
|
|
157
|
+
The field in the API tokens that contains the API scopes. With Tunnistamo this is usually `https://api.hel.fi/auth`.
|
|
158
|
+
When using the tester this can be anything as long as the corresponding setting in the GDPR API is the same.
|
|
159
|
+
|
|
160
|
+
### GDPR_API_QUERY_SCOPE and GDPR_API_DELETE_SCOPE
|
|
161
|
+
|
|
162
|
+
The GDPR query and delete scopes. These are provided to the API developers by the Profile-team. The value is usually
|
|
163
|
+
`[GDPR_API_AUDIENCE].gdprquery` and `[GDPR_API_AUDIENCE].gdprdelete`. e.g. `http://localhost:8080/exampleapi.gdprdelete`.
|
|
164
|
+
But in the tool and [helsinki-profile-gdpr-api](https://github.com/City-of-Helsinki/helsinki-profile-gdpr-api) configurations the values must be configured without the domain part. In this example they would be `exampleapi.gdprquery` and `exampleapi.gdprdelete`.
|
|
165
|
+
|
|
166
|
+
### GDPR_API_URL
|
|
167
|
+
|
|
168
|
+
The address of the GDPR API. The string `$profile_id` will be substituted with the value of **PROFILE_ID**. The string `$user_uuid` will be substituted with the value of **USER_UUID**. If there are no substitutions, the **PROFILE_ID will** be appended to the URL.
|
|
169
|
+
|
|
170
|
+
### PROFILE_ID
|
|
171
|
+
|
|
172
|
+
The value which will replace the string `$profile_id` in the **GDPR_API_URL**.
|
|
173
|
+
|
|
174
|
+
### USER_UUID
|
|
175
|
+
|
|
176
|
+
The value for the "sub" claim in the generated API tokens and the value which will replace the string `$user_uuid` in the **GDPR_API_URL**.
|
|
177
|
+
|
|
178
|
+
### LOA
|
|
179
|
+
|
|
180
|
+
The value for the "loa" (Level of assurance) claim in the generated API tokens. Possible values are `substantial` and `low`. See the [GDPR API Description](https://helsinkisolutionoffice.atlassian.net/wiki/spaces/KAN/pages/80969736/GDPR+API+Description#The-effect-of-authentication-level) for more information.
|
|
181
|
+
|
|
182
|
+
### SID
|
|
183
|
+
|
|
184
|
+
The value for the "sid" (Session ID) claim in the generated API tokens. The GDPR API doesn't need to use the session id,
|
|
185
|
+
but it's included for completeness' sake.
|
|
186
|
+
|
|
187
|
+
# Usage
|
|
188
|
+
|
|
189
|
+
The tool starts as an interactive prompt the user can use to run commands.
|
|
190
|
+
|
|
191
|
+
> Commands:
|
|
192
|
+
>
|
|
193
|
+
> help - This help\
|
|
194
|
+
> config - Show configuration\
|
|
195
|
+
> keys - Print public and private keys used in the OIDC Simulator\
|
|
196
|
+
> set - Set configuration value e.g. set USER_UUID=0000-000...\
|
|
197
|
+
> query - Make GDPR query request to the API\
|
|
198
|
+
> delete - Make GDPR delete request to the API\
|
|
199
|
+
> delete dryrun - Make GDPR delete dry-run request to the API\
|
|
200
|
+
> exit - Quit the GDPR API Tester
|
|
201
|
+
|
|
202
|
+
## Full example with Docker
|
|
203
|
+
|
|
204
|
+
### Example backend
|
|
205
|
+
|
|
206
|
+
Clone the [Example backend](https://github.com/City-of-Helsinki/example-backend-profile/) repository and copy the example env file to config.env.
|
|
207
|
+
|
|
208
|
+
```shell
|
|
209
|
+
git clone https://github.com/City-of-Helsinki/example-backend-profile/
|
|
210
|
+
cd example-backend-profile
|
|
211
|
+
cp config.env.example config.env
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Edit the example backend configuration file (config.env) and set the following values:
|
|
215
|
+
|
|
216
|
+
**Notice!** You must not use quotes around the values
|
|
217
|
+
|
|
218
|
+
ALLOWED_HOSTS=host.docker.internal
|
|
219
|
+
OIDC_AUDIENCE=http://example.com/exampleapi
|
|
220
|
+
OIDC_API_AUTHORIZATION_FIELD=http://example.com
|
|
221
|
+
OIDC_ISSUER=http://host.docker.internal:8888
|
|
222
|
+
GDPR_API_QUERY_SCOPE=exampleapi.gdprquery
|
|
223
|
+
GDPR_API_DELETE_SCOPE=exampleapi.gdprdelete
|
|
224
|
+
|
|
225
|
+
Build and start the example backend
|
|
226
|
+
|
|
227
|
+
```shell
|
|
228
|
+
docker build -t example-backend .
|
|
229
|
+
docker run -it -p 8000:8000 --env-file config.env example-backend
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### GDPR API Tester
|
|
233
|
+
|
|
234
|
+
See the [Running using Docker](#running-using-docker) section and set the following values in the configuration:
|
|
235
|
+
|
|
236
|
+
ISSUER=http://host.docker.internal:8888/
|
|
237
|
+
GDPR_API_AUDIENCE=http://example.com/exampleapi
|
|
238
|
+
GDPR_API_AUTHORIZATION_FIELD=http://example.com
|
|
239
|
+
GDPR_API_QUERY_SCOPE=exampleapi.gdprquery
|
|
240
|
+
GDPR_API_DELETE_SCOPE=exampleapi.gdprdelete
|
|
241
|
+
GDPR_API_URL=http://host.docker.internal:8000/gdpr-api/v1/user/$user_uuid
|
|
242
|
+
PROFILE_ID=65d4015d-1736-4848-9466-25d43a1fe8c7
|
|
243
|
+
USER_UUID=9e14df7c-81f6-4c41-8578-6aa7b9d0e5c0
|
|
244
|
+
LOA=substantial
|
|
245
|
+
SID=00000000-0000-4000-9000-000000000001
|
|
246
|
+
|
|
247
|
+
You should be able to send requests to the example backend after the GDPR API Tester starts. e.g. issuing the "query" command should yield something like this:
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
> query
|
|
251
|
+
|
|
252
|
+
Sending GDPR API request
|
|
253
|
+
GET http://host.docker.internal:8000/gdpr-api/v1/user/9e14df7c-81f6-4c41-8578-6aa7b9d0e5c0
|
|
254
|
+
Authorization header:
|
|
255
|
+
|
|
256
|
+
Bearer eyJhbG...QTQNBYW_A
|
|
257
|
+
|
|
258
|
+
Token claims:
|
|
259
|
+
|
|
260
|
+
{
|
|
261
|
+
"iss": "http://host.docker.internal:8888/",
|
|
262
|
+
"sub": "9e14df7c-81f6-4c41-8578-6aa7b9d0e5c0",
|
|
263
|
+
"aud": "http://example.com/exampleapi",
|
|
264
|
+
"exp": 1673519671,
|
|
265
|
+
"iat": 1673519071,
|
|
266
|
+
"auth_time": 1673519071,
|
|
267
|
+
"sid": "00000000-0000-4000-9000-000000000001",
|
|
268
|
+
"loa": "substantial",
|
|
269
|
+
"http://example.com": [
|
|
270
|
+
"exampleapi.gdprquery"
|
|
271
|
+
]
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
Response status code: 200
|
|
275
|
+
How the Profile back-end would interpret the response:
|
|
276
|
+
|
|
277
|
+
Success.
|
|
278
|
+
The response JSON:
|
|
279
|
+
{
|
|
280
|
+
"key": "EXAMPLE_DATA",
|
|
281
|
+
"children": [
|
|
282
|
+
{
|
|
283
|
+
"key": "USER",
|
|
284
|
+
"children": [
|
|
285
|
+
{
|
|
286
|
+
"key": "FIRST_NAME",
|
|
287
|
+
"value": ""
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"key": "LAST_NAME",
|
|
291
|
+
"value": ""
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
"key": "EMAIL",
|
|
295
|
+
"value": ""
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"key": "USERDATA",
|
|
301
|
+
"children": [
|
|
302
|
+
{
|
|
303
|
+
"key": "PET_NAME",
|
|
304
|
+
"value": null
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"key": "BIRTHDAY",
|
|
308
|
+
"value": null
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
}
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
>
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
# GDPR Flow
|
|
318
|
+
|
|
319
|
+
### Flow when the whole stack is in use
|
|
320
|
+
|
|
321
|
+
```mermaid
|
|
322
|
+
sequenceDiagram
|
|
323
|
+
actor User
|
|
324
|
+
participant Profile UI
|
|
325
|
+
participant Profile Backend
|
|
326
|
+
participant Service GDPR API
|
|
327
|
+
participant Tunnistamo
|
|
328
|
+
User->>+Profile UI: Download my data
|
|
329
|
+
Profile UI->>+Profile Backend: Get data
|
|
330
|
+
Profile Backend->>+Tunnistamo: Get API token
|
|
331
|
+
Tunnistamo-->>-Profile Backend: API token
|
|
332
|
+
Profile Backend->>+Service GDPR API: Get data
|
|
333
|
+
Service GDPR API->>+Tunnistamo: Get public key
|
|
334
|
+
Tunnistamo-->>-Service GDPR API: Public key
|
|
335
|
+
Service GDPR API->>Service GDPR API: Validate API token
|
|
336
|
+
Service GDPR API-->>-Profile Backend: Return data
|
|
337
|
+
Profile Backend-->>-Profile UI: Return data
|
|
338
|
+
Profile UI-->>-User: Return data
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Flow when using the GDPR API Tester
|
|
342
|
+
|
|
343
|
+
```mermaid
|
|
344
|
+
sequenceDiagram
|
|
345
|
+
actor Tester
|
|
346
|
+
participant GDPR API Tester
|
|
347
|
+
participant Service GDPR API
|
|
348
|
+
GDPR API Tester->>GDPR API Tester: Generate RSA key
|
|
349
|
+
Tester->>+GDPR API Tester: query
|
|
350
|
+
GDPR API Tester->>GDPR API Tester: Generate API token
|
|
351
|
+
GDPR API Tester->>+Service GDPR API: Get data
|
|
352
|
+
Service GDPR API->>+GDPR API Tester: Get public key
|
|
353
|
+
GDPR API Tester-->>-Service GDPR API: public key
|
|
354
|
+
Service GDPR API->>Service GDPR API: Validate API token
|
|
355
|
+
Service GDPR API-->>-GDPR API Tester: Return data
|
|
356
|
+
GDPR API Tester-->>-Tester: Display data
|
|
357
|
+
```
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
Helsinki Profile GDPR API Tester
|
|
2
|
+
================================
|
|
3
|
+
|
|
4
|
+
Profile GDPR API Tester is a command line tool for testing GDPR API implementations that conform to the Helsinki Profile GDPR API specification.
|
|
5
|
+
This tools main usage is to test the API Token authentication in the implemented GDPR API.
|
|
6
|
+
|
|
7
|
+
See [GDPR API Description](https://helsinkisolutionoffice.atlassian.net/wiki/spaces/KAN/pages/80969736/GDPR+API+Description) for more information about the GDPR API.
|
|
8
|
+
|
|
9
|
+
# Requirements
|
|
10
|
+
|
|
11
|
+
Python 3.10+ or Docker
|
|
12
|
+
|
|
13
|
+
# Installing / Running
|
|
14
|
+
|
|
15
|
+
## Running from a GitHub package using Docker
|
|
16
|
+
|
|
17
|
+
Copy [env.example](env.example) to your local filesystem as `.env` and change the settings to suit your environment. (See [configuration](#configuration))
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
docker run -i -p 8888:8888 --env-file .env ghcr.io/city-of-helsinki/profile-gdpr-api-tester
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Installing using pip
|
|
25
|
+
|
|
26
|
+
You can install this tool in your local Python environment by running
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
pip install gdpr-api-tester
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Running after installing with pip
|
|
33
|
+
|
|
34
|
+
Copy [env.example](env.example) to `.env` and change the settings to suit your environment. (See [configuration](#configuration))
|
|
35
|
+
|
|
36
|
+
Then run the command:
|
|
37
|
+
|
|
38
|
+
```shell
|
|
39
|
+
gdpr_api_tester
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Building and running using Docker
|
|
43
|
+
|
|
44
|
+
Clone this repository
|
|
45
|
+
|
|
46
|
+
```shell
|
|
47
|
+
git clone https://github.com/City-of-Helsinki/profile-gdpr-api-tester
|
|
48
|
+
cd profile-gdpr-api-tester
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Copy [env.example](env.example) to `.env` and change the settings to suit your environment. (See [configuration](#configuration))
|
|
52
|
+
|
|
53
|
+
```shell
|
|
54
|
+
cp env.example .env
|
|
55
|
+
$EDITOR .env
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Then build and run a Docker image:
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
docker build -t gdpr-api-tester .
|
|
62
|
+
docker run -i -p 8888:8888 --env-file .env gdpr-api-tester
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## Running from this repo
|
|
67
|
+
|
|
68
|
+
```shell
|
|
69
|
+
git clone https://github.com/City-of-Helsinki/profile-gdpr-api-tester
|
|
70
|
+
cd profile-gdpr-api-tester
|
|
71
|
+
cp env.example .env
|
|
72
|
+
python -m venv venv
|
|
73
|
+
source venv/bin/activate
|
|
74
|
+
pip install -r requirements.txt
|
|
75
|
+
python -m gdpr_api_tester
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
# Configuration
|
|
79
|
+
|
|
80
|
+
The tool reads configuration from environment variables and from a file named `.env`. There is an example env file ([env.example](env.example)) in the repository. You can use it as a base for your own configuration.
|
|
81
|
+
|
|
82
|
+
Following is a list of all the configuration options:
|
|
83
|
+
|
|
84
|
+
### ISSUER
|
|
85
|
+
|
|
86
|
+
The issuer in the generated API tokens and the address of the GDPR API Tester. The API must have connectivity to this address because the JWT token verification will fetch the public key from here.
|
|
87
|
+
|
|
88
|
+
### GDPR_API_AUDIENCE
|
|
89
|
+
|
|
90
|
+
The audience in the generated API tokens. i.e. The client id of the GDPR API.
|
|
91
|
+
|
|
92
|
+
### GDPR_API_AUTHORIZATION_FIELD
|
|
93
|
+
|
|
94
|
+
The field in the API tokens that contains the API scopes. With Tunnistamo this is usually `https://api.hel.fi/auth`.
|
|
95
|
+
When using the tester this can be anything as long as the corresponding setting in the GDPR API is the same.
|
|
96
|
+
|
|
97
|
+
### GDPR_API_QUERY_SCOPE and GDPR_API_DELETE_SCOPE
|
|
98
|
+
|
|
99
|
+
The GDPR query and delete scopes. These are provided to the API developers by the Profile-team. The value is usually
|
|
100
|
+
`[GDPR_API_AUDIENCE].gdprquery` and `[GDPR_API_AUDIENCE].gdprdelete`. e.g. `http://localhost:8080/exampleapi.gdprdelete`.
|
|
101
|
+
But in the tool and [helsinki-profile-gdpr-api](https://github.com/City-of-Helsinki/helsinki-profile-gdpr-api) configurations the values must be configured without the domain part. In this example they would be `exampleapi.gdprquery` and `exampleapi.gdprdelete`.
|
|
102
|
+
|
|
103
|
+
### GDPR_API_URL
|
|
104
|
+
|
|
105
|
+
The address of the GDPR API. The string `$profile_id` will be substituted with the value of **PROFILE_ID**. The string `$user_uuid` will be substituted with the value of **USER_UUID**. If there are no substitutions, the **PROFILE_ID will** be appended to the URL.
|
|
106
|
+
|
|
107
|
+
### PROFILE_ID
|
|
108
|
+
|
|
109
|
+
The value which will replace the string `$profile_id` in the **GDPR_API_URL**.
|
|
110
|
+
|
|
111
|
+
### USER_UUID
|
|
112
|
+
|
|
113
|
+
The value for the "sub" claim in the generated API tokens and the value which will replace the string `$user_uuid` in the **GDPR_API_URL**.
|
|
114
|
+
|
|
115
|
+
### LOA
|
|
116
|
+
|
|
117
|
+
The value for the "loa" (Level of assurance) claim in the generated API tokens. Possible values are `substantial` and `low`. See the [GDPR API Description](https://helsinkisolutionoffice.atlassian.net/wiki/spaces/KAN/pages/80969736/GDPR+API+Description#The-effect-of-authentication-level) for more information.
|
|
118
|
+
|
|
119
|
+
### SID
|
|
120
|
+
|
|
121
|
+
The value for the "sid" (Session ID) claim in the generated API tokens. The GDPR API doesn't need to use the session id,
|
|
122
|
+
but it's included for completeness' sake.
|
|
123
|
+
|
|
124
|
+
# Usage
|
|
125
|
+
|
|
126
|
+
The tool starts as an interactive prompt the user can use to run commands.
|
|
127
|
+
|
|
128
|
+
> Commands:
|
|
129
|
+
>
|
|
130
|
+
> help - This help\
|
|
131
|
+
> config - Show configuration\
|
|
132
|
+
> keys - Print public and private keys used in the OIDC Simulator\
|
|
133
|
+
> set - Set configuration value e.g. set USER_UUID=0000-000...\
|
|
134
|
+
> query - Make GDPR query request to the API\
|
|
135
|
+
> delete - Make GDPR delete request to the API\
|
|
136
|
+
> delete dryrun - Make GDPR delete dry-run request to the API\
|
|
137
|
+
> exit - Quit the GDPR API Tester
|
|
138
|
+
|
|
139
|
+
## Full example with Docker
|
|
140
|
+
|
|
141
|
+
### Example backend
|
|
142
|
+
|
|
143
|
+
Clone the [Example backend](https://github.com/City-of-Helsinki/example-backend-profile/) repository and copy the example env file to config.env.
|
|
144
|
+
|
|
145
|
+
```shell
|
|
146
|
+
git clone https://github.com/City-of-Helsinki/example-backend-profile/
|
|
147
|
+
cd example-backend-profile
|
|
148
|
+
cp config.env.example config.env
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Edit the example backend configuration file (config.env) and set the following values:
|
|
152
|
+
|
|
153
|
+
**Notice!** You must not use quotes around the values
|
|
154
|
+
|
|
155
|
+
ALLOWED_HOSTS=host.docker.internal
|
|
156
|
+
OIDC_AUDIENCE=http://example.com/exampleapi
|
|
157
|
+
OIDC_API_AUTHORIZATION_FIELD=http://example.com
|
|
158
|
+
OIDC_ISSUER=http://host.docker.internal:8888
|
|
159
|
+
GDPR_API_QUERY_SCOPE=exampleapi.gdprquery
|
|
160
|
+
GDPR_API_DELETE_SCOPE=exampleapi.gdprdelete
|
|
161
|
+
|
|
162
|
+
Build and start the example backend
|
|
163
|
+
|
|
164
|
+
```shell
|
|
165
|
+
docker build -t example-backend .
|
|
166
|
+
docker run -it -p 8000:8000 --env-file config.env example-backend
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### GDPR API Tester
|
|
170
|
+
|
|
171
|
+
See the [Running using Docker](#running-using-docker) section and set the following values in the configuration:
|
|
172
|
+
|
|
173
|
+
ISSUER=http://host.docker.internal:8888/
|
|
174
|
+
GDPR_API_AUDIENCE=http://example.com/exampleapi
|
|
175
|
+
GDPR_API_AUTHORIZATION_FIELD=http://example.com
|
|
176
|
+
GDPR_API_QUERY_SCOPE=exampleapi.gdprquery
|
|
177
|
+
GDPR_API_DELETE_SCOPE=exampleapi.gdprdelete
|
|
178
|
+
GDPR_API_URL=http://host.docker.internal:8000/gdpr-api/v1/user/$user_uuid
|
|
179
|
+
PROFILE_ID=65d4015d-1736-4848-9466-25d43a1fe8c7
|
|
180
|
+
USER_UUID=9e14df7c-81f6-4c41-8578-6aa7b9d0e5c0
|
|
181
|
+
LOA=substantial
|
|
182
|
+
SID=00000000-0000-4000-9000-000000000001
|
|
183
|
+
|
|
184
|
+
You should be able to send requests to the example backend after the GDPR API Tester starts. e.g. issuing the "query" command should yield something like this:
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
> query
|
|
188
|
+
|
|
189
|
+
Sending GDPR API request
|
|
190
|
+
GET http://host.docker.internal:8000/gdpr-api/v1/user/9e14df7c-81f6-4c41-8578-6aa7b9d0e5c0
|
|
191
|
+
Authorization header:
|
|
192
|
+
|
|
193
|
+
Bearer eyJhbG...QTQNBYW_A
|
|
194
|
+
|
|
195
|
+
Token claims:
|
|
196
|
+
|
|
197
|
+
{
|
|
198
|
+
"iss": "http://host.docker.internal:8888/",
|
|
199
|
+
"sub": "9e14df7c-81f6-4c41-8578-6aa7b9d0e5c0",
|
|
200
|
+
"aud": "http://example.com/exampleapi",
|
|
201
|
+
"exp": 1673519671,
|
|
202
|
+
"iat": 1673519071,
|
|
203
|
+
"auth_time": 1673519071,
|
|
204
|
+
"sid": "00000000-0000-4000-9000-000000000001",
|
|
205
|
+
"loa": "substantial",
|
|
206
|
+
"http://example.com": [
|
|
207
|
+
"exampleapi.gdprquery"
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
Response status code: 200
|
|
212
|
+
How the Profile back-end would interpret the response:
|
|
213
|
+
|
|
214
|
+
Success.
|
|
215
|
+
The response JSON:
|
|
216
|
+
{
|
|
217
|
+
"key": "EXAMPLE_DATA",
|
|
218
|
+
"children": [
|
|
219
|
+
{
|
|
220
|
+
"key": "USER",
|
|
221
|
+
"children": [
|
|
222
|
+
{
|
|
223
|
+
"key": "FIRST_NAME",
|
|
224
|
+
"value": ""
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"key": "LAST_NAME",
|
|
228
|
+
"value": ""
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"key": "EMAIL",
|
|
232
|
+
"value": ""
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"key": "USERDATA",
|
|
238
|
+
"children": [
|
|
239
|
+
{
|
|
240
|
+
"key": "PET_NAME",
|
|
241
|
+
"value": null
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"key": "BIRTHDAY",
|
|
245
|
+
"value": null
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
]
|
|
250
|
+
}
|
|
251
|
+
>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
# GDPR Flow
|
|
255
|
+
|
|
256
|
+
### Flow when the whole stack is in use
|
|
257
|
+
|
|
258
|
+
```mermaid
|
|
259
|
+
sequenceDiagram
|
|
260
|
+
actor User
|
|
261
|
+
participant Profile UI
|
|
262
|
+
participant Profile Backend
|
|
263
|
+
participant Service GDPR API
|
|
264
|
+
participant Tunnistamo
|
|
265
|
+
User->>+Profile UI: Download my data
|
|
266
|
+
Profile UI->>+Profile Backend: Get data
|
|
267
|
+
Profile Backend->>+Tunnistamo: Get API token
|
|
268
|
+
Tunnistamo-->>-Profile Backend: API token
|
|
269
|
+
Profile Backend->>+Service GDPR API: Get data
|
|
270
|
+
Service GDPR API->>+Tunnistamo: Get public key
|
|
271
|
+
Tunnistamo-->>-Service GDPR API: Public key
|
|
272
|
+
Service GDPR API->>Service GDPR API: Validate API token
|
|
273
|
+
Service GDPR API-->>-Profile Backend: Return data
|
|
274
|
+
Profile Backend-->>-Profile UI: Return data
|
|
275
|
+
Profile UI-->>-User: Return data
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Flow when using the GDPR API Tester
|
|
279
|
+
|
|
280
|
+
```mermaid
|
|
281
|
+
sequenceDiagram
|
|
282
|
+
actor Tester
|
|
283
|
+
participant GDPR API Tester
|
|
284
|
+
participant Service GDPR API
|
|
285
|
+
GDPR API Tester->>GDPR API Tester: Generate RSA key
|
|
286
|
+
Tester->>+GDPR API Tester: query
|
|
287
|
+
GDPR API Tester->>GDPR API Tester: Generate API token
|
|
288
|
+
GDPR API Tester->>+Service GDPR API: Get data
|
|
289
|
+
Service GDPR API->>+GDPR API Tester: Get public key
|
|
290
|
+
GDPR API Tester-->>-Service GDPR API: public key
|
|
291
|
+
Service GDPR API->>Service GDPR API: Validate API token
|
|
292
|
+
Service GDPR API-->>-GDPR API Tester: Return data
|
|
293
|
+
GDPR API Tester-->>-Tester: Display data
|
|
294
|
+
```
|
|
File without changes
|