Question

I am writing a test suite for an application (Utilizing Test::Class::Moose; Catalyst::Test) and have run into a bit of a snag. I have a test that checks that I get a successful response from the URL and then checks the title. Most of the tests pass, but a few URI's are redirecting to a login page. IE:

If I pass /foo/bar, I get the title I expect

                but

If I pass /foo/baz, it redirects to the login page. '

(In both cases I get a successful response : 200, and the authentication requirements are identical )

My question is: How does Catalyst::Test deal with user authentication and why would it pass authentication checks on some URI's and not others? The documentation is extremely vague in this regard and Dr. Google isn't returning anything helpful either.

Note: The code isn't 'Mine' so I can't post it, but I can give abstract examples if needed.

Was it helpful?

Solution

When using Catalyst::Test the request method may be of use to you where your URI's require Authentication credentials.

This method can take a HTTP::Request object which allows you to set up the request information beyond a URI string. Most notably as shown in the synopsis, you will want to set up the user agent to support passing in the credentials and cover things like persisting cookies which is the likely session state implementation.

See LWP::UserAgent for more information on this.

As to your questions considering why some URI's require authentication and some don't, it depends on how things are set up in code. Even if there is a general call to authenticate in the begin or auto action in the Root controller, the dispatch process may be overridden. Taking some time to digest the following may apply.

Introduction to Catalyst: Built-in actions in controllers/autochaining

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top