You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The User Tools utility provided by this blueprint allows for the easy management of test users via a json file included
3
+
The User Tools utility provided by this blueprint allows for the easy management of test users via a `users.json` file included
4
4
at the base of the repository.
5
5
6
6
## Table of Contents
@@ -10,56 +10,85 @@ at the base of the repository.
10
10
-[Using the User Tools class](#using-the-user-tools-class)
11
11
-[Managing Users](#managing-users)
12
12
-[Considering Security](#considering-security)
13
-
-[`retrieve_user()`: Retrieve User Details](#retrieve_user-retrieve-user-details)
13
+
-[`user_login()`: Log In as a User](#user_login-log-in-as-a-user)
14
14
-[Required Arguments](#required-arguments)
15
-
-[Returns](#returns)
16
15
-[Example Usage](#example-usage)
16
+
-[`retrieve_user()`: Retrieve User Details](#retrieve_user-retrieve-user-details)
17
+
-[Required Arguments](#required-arguments-1)
18
+
-[Returns](#returns)
19
+
-[Example Usage](#example-usage-1)
17
20
18
21
## Using the User Tools class
19
22
20
-
You can initialise the User Tools class by using the following code in your test file:
23
+
You can use the User Tools class by importing it in your test file:
21
24
22
-
from utils.user_tools import UserTools
25
+
```python
26
+
from utils.user_tools import UserTools
27
+
```
23
28
24
29
This module has been designed as a static class, so you do not need to instantiate it when you want to retrieve any user information.
25
30
26
31
## Managing Users
27
32
28
-
For this class, users are managed via the [users.json](../../users.json) file provided with this repository. For any new users you need to
29
-
add, the idea is to just add a new record, with any appropriate metadata you need for the user whilst they interact with your application.
33
+
For this class, users are managed via the [`users.json`](../../users.json) file provided with this repository. For any new users you need to add, simply add a new record with any appropriate metadata you need for the user whilst they interact with your application.
30
34
31
35
For example, adding a record like so (this example shows the entire `users.json` file):
32
36
33
-
{
34
-
"Documentation User": {
35
-
"username": "DOC_USER",
36
-
"roles": ["Example Role A"],
37
-
"unique_id": 42
38
-
}
39
-
}
40
-
41
-
The data you require for these users can be completely customised for what information you need, so whilst the example shows `username`, `roles`
42
-
and `unique_id` as possible values we may want to use, this is not an exhaustive list. The key that is used (so in this example, `"Documentation User"`)
43
-
is also customisable and should be how you want to easily reference retrieving this user in your tests.
37
+
```json
38
+
{
39
+
"Hub Manager State Registered at BCS01": {
40
+
"username": "BCSS401",
41
+
"roles": [
42
+
"Hub Manager State Registered, Midlands and North West"
43
+
]
44
+
}
45
+
}
46
+
```
44
47
45
48
### Considering Security
46
49
47
-
An important note on managing users in this way is that passwords or security credentials should **never** be stored in the `users.json` file. These
48
-
are considered secrets, and whilst it may be convenient to store them in this file, it goes against the
50
+
An important note on managing users in this way is that passwords or security credentials should **never** be stored in the `users.json` file. These are considered secrets, and whilst it may be convenient to store them in this file, it goes against the
49
51
[security principles outlined in the Software Engineering Quality Framework](https://github.com/NHSDigital/software-engineering-quality-framework/blob/main/practices/security.md#application-level-security).
50
52
51
53
With this in mind, it's recommended to do the following when it comes to managing these types of credentials:
52
54
53
-
- When running locally, store any secret values in a local configuration file and set this file in `.gitignore` so it is not committed to the codebase.
55
+
- When running locally, store any secret values in a local configuration file such as `local.env`. This file is created by running the script [`setup_env_file.py`](../../setup_env_file.py) and is included in `.gitignore` so it is not committed to the codebase.
54
56
- When running via a CI/CD process, store any secret values in an appropriate secret store and pass the values into pytest at runtime.
55
57
58
+
## `user_login()`: Log In as a User
59
+
60
+
The `user_login()` method allows you to log in to the BCSS application as a specified user. It retrieves the username from the `users.json` file and the password from the `local.env` file (using the `BCSS_PASS` environment variable).
0 commit comments