Skip to content

Conversation

@bubba1e
Copy link

@bubba1e bubba1e commented Jul 6, 2021

Reference Issues

Multiple Authenticators

Changes

  • The $authenticator variable was changed to an array and renamed to $authenticators to allow multiple authenticators
  • The authentication function has been changed to try each authenticator until one of them works or there are none left

@bubba1e bubba1e changed the title Allow multiple authenticator classes Issue/94 - Multiple Authenticators Jul 6, 2021
@dhensby
Copy link
Contributor

dhensby commented Jul 6, 2021

Definitely a nice addition, but I think we need some tests to cover this change

@bubba1e
Copy link
Author

bubba1e commented Jul 7, 2021

The tests now cover multiple authenticators.


$_SERVER['PHP_AUTH_USER'] = '[email protected]';

$response = Director::test($url, $data, null, 'PUT');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't shoe-horn a fairly fundamental authentication test into another unrelated test.

Please can you create a new test function like testApiAccess which adds additional authenticators and then asserts that the second authenticator works even if the first fails?

Director::config()->set('alternate_base_url', $this->baseURI);
RestfulServer::config()->set('authenticators', [
BasicRestfulAuthenticator::class,
EmailOnlyAuthenticator::class,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't add this authenticator to all tests if they don't need/want it as it may result in unintended side-affects in future tests. Just add it to the specific test for this situation.

}

/** @var null|Member $member */
$member = Member::get()->find('Email', $_SERVER['PHP_AUTH_USER']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a very good way to perform the test because we could see tests passing that shouldn't if (for example) the first authenticator has a bug that means passwords are not validated properly.

You could either create an actual mock instance of an authenticator (assuming there's an interface to mock) or create some kind of hard-coded token authenticator (eg: if AUTH_USER === 'SOME-TOKEN' return a user).

Ideally this user will be a new user added to the fixtures too.

@dhensby
Copy link
Contributor

dhensby commented Jul 8, 2021

Thanks for the work on this @nykkl - but we need to make the test a bit more specific / thorough I think.

@NightJar
Copy link
Contributor

I also feel this should target the master branch, as it alters critical configuration API in a non backwards compatible manner.
To this end would you also like to supply some upgrade documentation about what someone who uses this module should do in order to update it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants