Skip to content

Improve (even more) the use of multiple handler in portal unit tests

Maxime Besson requested to merge improve-portal-unit-tests-multiple-handlers into v2.0

This MR improves !438 (merged) even more by moving all the multi-handler logic into the "register" function

No more "switch", now, the only times you need to explicitely switch handlers is when you call a class handler method (checkConf) from unit tests directly. This can be done with the new withHandler wrapper:

withHandler( 'op', sub { $op->p->HANDLER->checkConf(1) } );

I have removed all switch($xx) statements from the test suite, from now on, they are automatically performed when invoking the _get or _post method on client objects (see the wrapper definition in register)

This new implementation also supports "stacking" handlers, which can happen when a portal with handler "rp" calls another portal with handler "op". This means that complex test such as t/35-REST-config-backend.t which perform HTTP requests during instanciation also work.

As a bonus, I added a Logger implementation that displays the handler stack nicely:

DEBUG=1 prove t/32-Auth-and-issuer-OIDC-authorization_code.t

# Request on RP is now clearly indicated:
[rp] [info] New request Lemonldap::NG::Portal::Main GET /

# Request on OP:
[op] [info] New request Lemonldap::NG::Portal::Main GET /oauth2/authorize?response_type=code&state=1706044640_37651&nonce=0yP2fr80AqBknj0-jOpoxg&redirect_uri=http%3A%2F%2Fauth.rp.com%2F%3Fopenidconnectcallback%3D1&client_id=rpid&scope=openid+profile+email&my_param=my+value&max_age=30&display=&acr_values=loa-32+customacr-1

# Even RP to OP requests are properly marked:
[rp->op] [info] New request Lemonldap::NG::Portal::Main POST /oauth2/token

This will make troubleshooting unit tests a LOT, LOT, LOT easier. And hopefully, writing them, too 😄

Merge request reports

Loading