Tuesday 5 October 2021

Properly test a Rails app with shibboleth auth

A Rails app with Shibboleth is not as easy to test as an app with say LDAP authentication. 

Functional tests work, but at a cost: the ENV name changes. In production (mod_passenger) the surname might be 'sn'. In test it is 'HTTP_SN'.

Sometime people write some env-driven if blocks to stub a user's login in development. Each time you need to change user's data you need to fix the controller.

The solution is:

  • outfactor the data fetching from ENV is a custom class;
  • use system test to mock the class above.

Some source code on github shows you the details.

Check the system test:

test/system/login_users_test.rb
The translation class is in:
app/lib