Commit 12e5717
committed
feat: initial authz API impl
This adds a new API for authorization, defined in `src/middleware/authz.js`,
which is centered around two key functions: `authz` and `authzLevel`. Each
returns a middleware function which applies the requested authorization
checks. For `authz`, if the authorization checks fail, then the request
fails. For `authzLevel`, if the authorization checks fail, then the request
continues but without an authorization level being set on the request
context.
In addition to these top-level APIs, this introduces a set of pre-defined
checks, plus two check combinators, which collectively will enable
CVE Services endpoints to define the authorization checks they require,
all in one place.
This is intended to replace the combination of existing authorization
middleware functions and ad-hoc authorization checks performed throughout
a number of endpoints. This commit *does not* include any replacement of
existing authorization checks, only the introduction of the new API.
For test, note the following:
Mocha doesn't isolate tests in their own process, which means when
the tests are running they're actually all sharing a singleton
instance of the Express app. This is a problem for the authz
testing specifically, because it modifies a piece of global
state (`useNewAuthzApi`) to select at runtime whether to use
the old or new versions of the authorization API.
To deal with this, this commit also ensures that authz tests
are isolated in their own, separate run of Mocha.
We also shim the method Set.prototype.intersection.
The Set.prototype.intersection method was added to the Set
type in Node.js version 22. Currently, CVE Services uses an
older version of Node and so we need this shim to ensure
the API runs.
We are planning to upgrade to Node 24 soon, in which case
this shim will become unecessary.
Signed-off-by: Andrew Lilley Brinker <abrinker@mitre.org>1 parent 51e1e0f commit 12e5717
10 files changed
Lines changed: 1512 additions & 305 deletions
File tree
- src
- controller/cve.controller
- middleware
- repositories
- test/integration-tests/cve
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
108 | | - | |
109 | | - | |
| 109 | + | |
| 110 | + | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
583 | 584 | | |
584 | 585 | | |
585 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
586 | 591 | | |
587 | 592 | | |
588 | 593 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
0 commit comments