Commit aa04b30
authored
[ENH] replaced hardcoded test server admin key with env variable and secrets (openml#1568)
#### Metadata
* Reference Issue: openml#1529
* New Tests Added: Yes
* Documentation Updated: No
* Change Log Entry: <!-- Short String, example: "Add new function `foo()` to module `bar`"; or "Fixes a bug with `bar`" -->
#### Details
this PR is made to remove the hardcoded test server admin key from the codebase and replace it with environment variable-based authentication.
## Summary
- in `openml/config.py` Added a new environment variable constant for the test server admin key:
```python
OPENML_TEST_SERVER_ADMIN_KEY_ENV_VAR = "OPENML_TEST_SERVER_ADMIN_KEY"
```
- Testing Base Class Updated in `openml/testing.py`. Modified the `TestBase` class to read the admin key from an environment variable instead of using a hardcoded value:
**Before**:
```python
admin_key = "abc"
```
**After**:
```python
admin_key = os.environ.get(openml.config.OPENML_TEST_SERVER_ADMIN_KEY_ENV_VAR)
```
**Note**:
- The admin key is now `None` by default when the environment variable is not set
- Tests requiring the admin key will fail gracefully if the key is not available
Also in the tests, Added `pytest.skipif` decorators to tests that require admin privileges in the following test files:
#### `tests/test_openml/test_config.py`
**Test**: `test_switch_to_example_configuration`
**Added decorator**:
```python
@pytest.mark.skipif(
not os.environ.get(openml.config.OPENML_TEST_SERVER_ADMIN_KEY_ENV_VAR),
reason="Test requires admin key. Set OPENML_TEST_SERVER_ADMIN_KEY environment variable.",
)
```
#### `tests/test_datasets/test_dataset_functions.py`
**Test**: `test_data_status`
**Added decorator**:
```python
@pytest.mark.skipif(
not os.environ.get(openml.config.OPENML_TEST_SERVER_ADMIN_KEY_ENV_VAR),
reason="Test requires admin key. Set OPENML_TEST_SERVER_ADMIN_KEY environment variable.",
)
```
**Note**:
- These tests will be automatically skipped if the admin key is not provided
- Clear skip reason is displayed when tests are skipped
- No failures or errors when running tests locally without the admin key
### 4. CI Configuration Update (`.github/workflows/test.yml`)
Added the environment variable to all test execution steps in the GitHub Actions workflow:
**Steps updated**:
- Run tests on Ubuntu Test
- Run tests on Ubuntu Production
- Run tests on Windows
**Added to each step**:
```yaml
env:
OPENML_TEST_SERVER_ADMIN_KEY: ${{ secrets.OPENML_TEST_SERVER_ADMIN_KEY }}
```
**Impact**:
- CI will use the secret stored in GitHub repository settings
- Tests requiring admin privileges will run in CI
- The actual key value is never exposed in logs or code
@PGijsbers this requires someone to put the admin key in the github secrets which would be a critical step.
# Update on reviews
the configurations should be done from openml config files in `./.openml/config` for directory level configurations, instead of the added responsibility of a new `.env` file and dependencies. in case of local testing the concerned tests would be skipped in case no key is provided.1 parent 06ac6d0 commit aa04b30
File tree
6 files changed
+24
-2
lines changed- .github/workflows
- openml
- tests
- test_datasets
- test_openml
6 files changed
+24
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
| |||
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| 126 | + | |
| 127 | + | |
124 | 128 | | |
125 | 129 | | |
126 | 130 | | |
| |||
136 | 140 | | |
137 | 141 | | |
138 | 142 | | |
| 143 | + | |
| 144 | + | |
139 | 145 | | |
140 | 146 | | |
141 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
99 | 110 | | |
100 | 111 | | |
101 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
602 | 606 | | |
603 | 607 | | |
604 | 608 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
0 commit comments