Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Application Testing, Mocking Apache Headers/Environment

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


brainbuz at brainbuz

Apr 12, 2012, 12:39 PM

Post #1 of 5 (364 views)
Permalink
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 [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


jjn1056 at yahoo

Apr 15, 2012, 12:34 PM

Post #2 of 5 (341 views)
Permalink
Re: Application Testing, Mocking Apache Headers/Environment [In reply to]

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 <brainbuz [at] brainbuz>
>To: 'The elegant MVC web framework' <catalyst [at] lists>
>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 [at] lists
>Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
>Dev site: http://dev.catalyst.perl.org/
>
>
>


brainbuz at brainbuz

Apr 15, 2012, 11:11 PM

Post #3 of 5 (341 views)
Permalink
RE: Application Testing, Mocking Apache Headers/Environment [In reply to]

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:jjn1056 [at] yahoo]
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 <brainbuz [at] brainbuz
[1]>
TO: 'The elegant MVC web framework' <catalyst [at] lists
[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 [at] lists [3]
Listinfo:
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
[4]
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/ [5]
Dev site:
http://dev.catalyst.perl.org/ [6]



Links:
------
[1]
mailto:brainbuz [at] brainbuz
[2] mailto:catalyst [at] lists
[3]
mailto:Catalyst [at] lists
[4]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
[5]
http://www.mail-archive.com/catalyst [at] lists/
[6]
http://dev.catalyst.perl.org/


bobtfish at bobtfish

Apr 16, 2012, 12:58 AM

Post #4 of 5 (339 views)
Permalink
Re: Application Testing, Mocking Apache Headers/Environment [In reply to]

On 16 Apr 2012, at 07:11, brainbuz wrote:

> 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 }’);
>

Writing into the context object like this is fairly disrecommended - using the stash (or adding accessors on your context) is probably nicer..

Also, the authentication framework can probably do most of the heavy lifting for you instead of doing this manually…

Anyway, no matter - the answer you're probably looking for is to use Plack::Middleware::ForceEnv

Cheers
t0m


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


brainbuz at brainbuz

Apr 16, 2012, 12:47 PM

Post #5 of 5 (339 views)
Permalink
Re: Application Testing, Mocking Apache Headers/Environment [In reply to]

> - 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 [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.