Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent assertion error when using the withLoggedIn test helper. #136

Closed

Conversation

mikesname
Copy link
Contributor

Access the cookie params via the protected members of CookieTokenAccessor, rather than via the (deprecated) members of AuthConfig, which now throw an error.

I trust it's not this change which is causing the cache-related test failures!

Access the cookie params via the protected members of `CookieTokenAccessor`,
rather than via the (deprecated) members of `AuthConfig`, which now throw
an error.

I trust it's not this change which is causing the cache-related test failures!
@gakuzzzz
Copy link
Member

gakuzzzz commented Jun 9, 2015

Good catch! thanks!

However, if the config parameter does not use CookieTokenAccessor, the tests what use this config will be failed.

It need to use config.tokenAccessor

@mikesname
Copy link
Contributor Author

Aye, right you are 😄

I looked at using the tokenAccessor but none of the relevant params are exposed in the trait... do you have a nicer way in mind?

@gakuzzzz
Copy link
Member

mmm, It's a bit difficult...
TokenAccessor should teach the way how a request has token to FakeRequest.
However play2-auth core should not depends on play2-auth-test and play2-test modules...

@gakuzzzz gakuzzzz mentioned this pull request Jun 19, 2015
@mikesname
Copy link
Contributor Author

I changed the PR so instead of extending the CookieTokenAccessor, the helper just blows up if your AuthConfig isn't using one. Not a nice solution, but I can't think of anything better without much larger changes.

@gakuzzzz
Copy link
Member

gakuzzzz commented Jul 5, 2015

Thanks for proposal!

I had consider this problem, we provides a way what any TokenAccessor can test.
So I intoroduce a way that skip tokenaccessor.extract

private[auth] def extractToken(request: RequestHeader): Option[AuthenticityToken] = {
if (play.api.Play.isTest(play.api.Play.current)) {
request.headers.get("PLAY2_AUTH_TEST_TOKEN") orElse tokenAccessor.extract(request)
} else {
tokenAccessor.extract(request)
}
}

fakeRequest.withHeaders("PLAY2_AUTH_TEST_TOKEN" -> token)

@gakuzzzz gakuzzzz closed this Jul 5, 2015
@mikesname
Copy link
Contributor Author

👍 Nice one, that's a much better solution!

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.

2 participants