Commit Graph

6 Commits

Author SHA1 Message Date
Slavi Pantaleev
e59f5d5502 Make Match() with empty list not return a positive result
Now that we use Match() in allowAdmin() as well, it's awkward to
have it return `true` when called with an empty admin list.
No admins defined was taken to mean "everyone is an admin".

We can either have a `len(users) == 0` check in `allowAdmin` which
rejects the request, or we can change `Match()` so that it doesn't
return positive responses when called with an empty list. Doing the
latter sounds better. It's more natural that matching against an empty list
will yield "no match".
2022-08-29 14:10:52 +03:00
Aine
6623251695 refactored 2022-08-29 12:30:43 +03:00
Slavi Pantaleev
275ccbd9e5 Implement feedback 2022-08-27 08:11:36 +03:00
Slavi Pantaleev
bb754f9aa8 Simplify MatchUserWithAllowedRegexes
This used to return an error back when it was dealing with wildcards
(which may or may not have compiled to a valid regex).

But it now deals with pre-compiled regexes and has no chance of failing,
so we need no `error` returns.
2022-08-27 07:50:43 +03:00
Slavi Pantaleev
f8a168b8e7 Add a few more unit test cases 2022-08-27 07:50:43 +03:00
Slavi Pantaleev
8ad2e29930 Add support for configuring user whitelisting
This does not do anything useful just yet.
It will be hooked to access control checks later on.

Wildcards are converted to regular expressions, because it was simpler
to do that than to write (or include) some ugly wildcard matcher library.
It also provides more flexibility, should we wish to use it later.
Regular expressions should also work well performance-wise.

We compile wildcards to regexes early on (during configuration
processing) and fail if we detect a bad pattern. This is meant to
catch various problems (typos or other mistakes) that could happen.

For this to work, configuration building had to be redone, since it can
now return an error. This may be useful in the future for validating
other configuration settings.

Related to https://gitlab.com/etke.cc/postmoogle/-/issues/1
2022-08-27 07:50:41 +03:00