Skip to content

Conversation

@wouterj
Copy link
Member

@wouterj wouterj commented Mar 7, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #26839
License MIT
Doc PR tbd

This finishes #32850 original description:

I know this won't work for 100% of our users ... but the goal is to make life easier to most of them. Thanks!

A custom ConcreteToken test-object is created as suggested by @linaori, to not bind this token to any specific implementation (as other implementations aren't fully compatible with eachother).

@carsonbot carsonbot added Status: Needs Review DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature labels Mar 7, 2020
@wouterj wouterj force-pushed the pull-32850 branch 2 times, most recently from bdffecd to df54a4b Compare March 8, 2020 11:40
}

if (!$user instanceof UserInterface) {
throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::class, \is_object($user) ? \get_class($user) : \gettype($user)));
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if I need to use the get_debug_type() function here already, or if #35945 has to be merged first.

/**
* @param UserInterface $user
*/
public function loginUser($user, string $firewallContext = 'main'): self
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing the typehint allowed me to have a bit nicer error message when Security is not installed.

@wouterj
Copy link
Member Author

wouterj commented Mar 8, 2020

build failures are unrelated (HttpClient is failing)

}

$client->request('GET', '/'.($firewallContext ?? 'main').'/user_profile');
$this->assertEquals('Welcome '.$username.'!', $client->getResponse()->getContent());
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no assertion on the roles, I'd suggest to add some, to make sure roles are passed to the user and token, WDYT?


$client->request('GET', '/main/user_profile');
$this->assertEquals('Welcome the-username!', $client->getResponse()->getContent());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What about adding some tests to check for users that are not in the provider?

Copy link
Member Author

Choose a reason for hiding this comment

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

It has to be in the user provider (as Symfony reloads the user upon every requests and if the user changed (i.e. is no longer available), the user is logged out). Do you mean adding a test that the request is unsuccesfull?

@fabpot
Copy link
Member

fabpot commented Mar 11, 2020

Thank you @wouterj.

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

Labels

DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature Status: Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simpler testing of security protected resources

6 participants