forked from RedHatProductSecurity/rapidast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[authentication] named scanner broke auth factory (RedHatProductSecur…
…ity#127) The authentication factory expected a fixed string for the scanners, to get to the authentication type. This was broken by the named scanner (e.g.: `zap_anonymous`). This commit fixes that. Also, while at it, I tidied a little: - moved the factory into its own file - improved the dev documentation for authentication
- Loading branch information
Showing
4 changed files
with
64 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
########################################################### | ||
# AUTHENTICATION HELPERS # | ||
# - authentication factory # | ||
########################################################### | ||
|
||
|
||
def generic_authentication_factory(): | ||
"""Decorator factory for generic authentication. | ||
First create the decorator: | ||
@generic_authentication_factory("zap") | ||
def authentication_factory(self): | ||
[ default action. i.e.: probably raise error] | ||
Then populate it by registering methods: | ||
@authentication_factory.register(None) | ||
def authentication_set_anonymous(self): | ||
[return authentication of type `None`] | ||
""" | ||
|
||
def config_authentication_dispatcher(func): | ||
"""This is intended to be a decorator to register authentication functions | ||
The function passed during creation will be called in case no suitable functions are found. | ||
i.e.: it should raise an error. | ||
It is possible to retrieve an authenticator by calling <dispatcher>.dispatch(<version>) | ||
This may be used for testing purpose | ||
""" | ||
registry = {} # "method" -> authenticator() | ||
|
||
registry["error"] = func | ||
|
||
def register(method): | ||
def inner(func): | ||
registry[method] = func | ||
return func | ||
|
||
return inner | ||
|
||
def decorator(scanner): | ||
authenticator = scanner.my_conf("authentication.type") | ||
func = registry.get(authenticator, registry["error"]) | ||
return func(scanner) | ||
|
||
def dispatch(scanner): | ||
return registry.get(scanner, registry["error"]) | ||
|
||
decorator.register = register | ||
decorator.registry = registry | ||
decorator.dispatch = dispatch | ||
|
||
return decorator | ||
|
||
return config_authentication_dispatcher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters