I have this login scheme in my application.rb controller that looks like this: (pretty must straight from the rails recipes book): def check_authorization @user=User.find(session[:user]) unless @user.roles.detect {|role| role.rights.detect{|right| right.action == action_name && right.controller == self.class.controller_path } } render :text => "You are not authroized to preform this action", :status => 403 return false end end This works fine, but It makes it hard for me to functional test my controllers. Because now when I run my functional tests they all fail with 403 authentication errors. How can I login on my functional tests ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Roelofs
2007-Sep-12 17:39 UTC
Re: Functional testing controllers that rely authentication
On 9/12/07, eggie5 <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I have this login scheme in my application.rb controller that looks > like this: (pretty must straight from the rails recipes book): > > def check_authorization > @user=User.find(session[:user]) > > unless @user.roles.detect {|role| > role.rights.detect{|right| > right.action == action_name && > right.controller == self.class.controller_path > } > } > > render :text => "You are not authroized to preform this > action", :status => 403 > return false > end > end > > This works fine, but It makes it hard for me to functional test my > controllers. Because now when I run my functional tests they all fail > with 403 authentication errors. > > How can I login on my functional tests ? > > > > >def setup session[:user] = 1 end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Roelofs
2007-Sep-12 17:40 UTC
Re: Functional testing controllers that rely authentication
On 9/12/07, Jason Roelofs <jameskilton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 9/12/07, eggie5 <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I have this login scheme in my application.rb controller that looks > > like this: (pretty must straight from the rails recipes book): > > > > def check_authorization > > @user=User.find(session[:user]) > > > > unless @user.roles.detect {|role| > > role.rights.detect{|right| > > right.action == action_name && > > right.controller == self.class.controller_path > > } > > } > > > > render :text => "You are not authroized to preform this > > action", :status => 403 > > return false > > end > > end > > > > This works fine, but It makes it hard for me to functional test my > > controllers. Because now when I run my functional tests they all fail > > with 403 authentication errors. > > > > How can I login on my functional tests ? > > > > > > > > > > > def setup > session[:user] = 1 > endSorry def setup [ default setup stuff here] @request.session[:user] = 1 end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, Also for anyone out there, don''t forget to include any fixtures that you code will you at any point during this test. For me that was including the rights & roles fixtures that my authentication controller uses. On Sep 12, 10:40 am, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9/12/07, Jason Roelofs <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > On 9/12/07, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have this login scheme in my application.rb controller that looks > > > like this: (pretty must straight from the rails recipes book): > > > > def check_authorization > > > @user=User.find(session[:user]) > > > > unless @user.roles.detect {|role| > > > role.rights.detect{|right| > > > right.action == action_name && > > > right.controller == self.class.controller_path > > > } > > > } > > > > render :text => "You are not authroized to preform this > > > action", :status => 403 > > > return false > > > end > > > end > > > > This works fine, but It makes it hard for me to functional test my > > > controllers. Because now when I run my functional tests they all fail > > > with 403 authentication errors. > > > > How can I login on my functional tests ? > > > def setup > > session[:user] = 1 > > end > > Sorry > > def setup > [ default setup stuff here] > > @request.session[:user] = 1 > end--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---