RE: [Catalyst] Application Testing, Mocking Apache Headers/Environment
In my auto action I have something like: $c-{ USERNAME } = $c-engine-env-{ HTTP_COOKIE } ;#Authenticated via apache 2.4 mod_auth_form $c-{ USERRIGHTS } = $c-model( 'method returning a ref to a list of the rights for $c-{ USERNAME }'); In a controller I would like to test There is code that checks user-rights, if it fails it redirects to an error page. I would like to write a sequence of tests that checks the controller for users with different rights where some users are expected to get a redirect and others might see different responses. I'm still trying to work out controller testing so I don't have functional code to explain but if you pardon the following for not being quite workable code. my $user1 = 'restricted' ; my $user2 = 'privileged' ; my $user3 = 'hardworker' ; $test_object-{ username = $user1 } ; redirects_ok( $test_object-('/pageimtesting'), 'restricted user got sent elsewhere' ) ; $test_object-{ username = $user2 } ; content_contains( $test_object-('/pageimtesting'), 'exalted one', 'grovelled for privileged user' ) ; $test_object-{ username = $user3 } ; content_contains( $test_object-('/pageimtesting'), 'well do something', 'told worker to do something.' ) ; FROM: John Napiorkowski [mailto:jjn1...@yahoo.com] SENT: Sunday, April 15, 2012 3:35 PM TO: The elegant MVC web framework SUBJECT: Re: [Catalyst] Application Testing, Mocking Apache Headers/Environment John, Could you give us a bit more information? For example do you have a test case you are trying to write, but can't? I'll a little confused as to what you are trying to do and maybe seeing more code would help. Oh, and Just FYI the newer versions of Catalyst move the env access from engine to request, and if you are planning of making heavy use of that I'd consider upgrading, so that you won't have compatibility issues later. John - FROM: John Karr brain...@brainbuz.org [1] TO: 'The elegant MVC web framework' catalyst@lists.scsys.co.uk [2] SENT: Thursday, April 12, 2012 3:39 PM SUBJECT: [Catalyst] Application Testing, Mocking Apache Headers/Environment I am trying to test an application that is deployed behind a proxy and which is dependent on obtaining information from the request through $c-engine-env this information includes the logged in user and client ip address. I've been using the config file to provide override values, however, this is not helpful for testing multiple values. ___ List: Catalyst@lists.scsys.co.uk [3] Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst [4] Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ [5] Dev site: http://dev.catalyst.perl.org/ [6] Links: -- [1] mailto:brain...@brainbuz.org [2] mailto:catalyst@lists.scsys.co.uk [3] mailto:Catalyst@lists.scsys.co.uk [4] http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst [5] http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ [6] http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Application Testing, Mocking Apache Headers/Environment
- the answer you're probably looking for is to use Plack::Middleware::ForceEnv Thanks I peeked at the documentation it looks like exactly the approach I wanted to take. The documentation is brief and the tests are all directly against plackup. You wouldn't happen to have some handy examples you could post? ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Providing a REST API from behind Apache/FastCGI?
Newer versions of apache make some security changes so apache, even though you don't think any access control is being applied on the server side, might be blocking it by default (although that should be a 403 rather than 401). You could try a block like this: Location /uri_for/my/app.fcgi Order Allow,Deny Allow From All Satisfy Any /Location I wrote an article on deploying starman with apache in the 2011 catalyst advent calendar, with some errata on my blog, you might want to consider switching, although you would still run afoul of tighter apache defaults if that is indeed your problem. On 2013-11-08 15:54, Dan Lowe wrote: I have begun development of a RESTful API (using Catalyst::Controller::REST), intending to authenticate with basic HTTP authentication. Using the myproject_server.pl debug server, everything works fine. I send the GET, an Authorization: and an Accept: header, and I get a 200 response followed by JSON result. When I move this from dev to test, which means it goes behind mod_fastcgi, it stops working. Every request gets back 401 Unauthorized. As far as I can tell, the Authorization header is not being passed through to Catalyst. Note that my main interactive application uses HTML form auth and cookies/sessions, so this is our first use case involving HTTP basic authentication. Things I have already tried: 1. Adding -pass-header Authorization to the FastCgiExternalServer parameter in httpd.conf tcpdump tells me that the Authorization: Basic xxx is being sent to the server on port 4900, but it never actually gets through to where my req object can use it, e.g. $c-req-header('Authorization') is undef. 2. Rewriting the Authorization header as an env var RewriteCond %{HTTP:Authorization} ^(.+) RewriteRule ^(.*)$ $1 [E=HTTP_AUTHORIZATION:%1,PT] This turns out not to help because the environment seen by the fastcgi server is that of the user who started it, not the environment Apache is running in. Dumping the contents of %ENV shows that this env var is not available to Catalyst. 3. SSLOptions +StdEnvVars See #2, it sets env vars in the wrong environment. Has anyone had this problem and knows of some solution? I'm out of ideas at this point... Thanks, Dan ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/