undefined method `+' for nil:NilClass in sample saml application - ruby-on-rails

Trying to follow the setup here to create a simple SAML application (full project I got here).
I went through and did the setup
bundle install
rails s
This went fine, but when I navigate to
http://localhost:3000/
I get hit with
NoMethodError in SamlController#init
undefined method `+' for nil:NilClass
Extracted source (around line #9):
def init
request = OneLogin::RubySaml::Authrequest.new
direct_to(request.create(saml_settings))
end
def consume
I added some logging to check nil status of request and saml_settings but that seems to return false for both of them
puts request.nil?
puts saml_settings.nil?
Error trace:
Processing by SamlController#init as HTML
false
false
Created AuthnRequest: <samlp:AuthnRequest AssertionConsumerServiceURL='http://localhost:3000/saml/consume' ID='_394fa0a0-f313-0135-85a4-6a0001e18280' IssueInstant='2018-02-13T17:42:45Z' Version='2.0' xmlns:saml='urn:oasis:names:tc:SAML:2.0:assertion' xmlns:samlp='urn:oasis:names:tc:SAML:2.0:protocol'><saml:Issuer>http://localhost:3000/saml/consume</saml:Issuer></samlp:AuthnRequest>
Completed 500 Internal Server Error in 15ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `+' for nil:NilClass):
app/controllers/saml_controller.rb:9:in `init'
(Note: the error is line 5, it says line 9 for me because of debug logging I added)
I'm not too sure what else it could be, not sure what method it can't find and what is nil?
I have never messed with ruby stuff, but from my initial looks I'm not sure where the nil is coming from, the logs show the request being created so not sure. Any help would be appreciated, thanks!

Firstly I think you're using a pretty old ruby-saml gem version. That might be the problem.
I haven't tested your code, but it seems to me that you forgot to set idp_sso_target_url in your settings, and apparently that's the only place it can throw the exception you got. https://github.com/onelogin/ruby-saml/blob/v1.1.2/lib/onelogin/ruby-saml/authrequest.rb#L39

Posting the answer here, turns out that i was using a metadata url for the OKTA_METADATA environment variable.
Had to modify
settings = idp_metadata_parser.parse(ENV['OKTA_METADATA'])
to
settings = idp_metadata_parser.parse_remote(ENV['OKTA_METADATA'])
where
OKTA_METADATA=http://blahblahblah.com/metadata

Related

prerendering in react_on_rails app is throwing error

Whenever I switch prerendering to true for my react component in my rails view I'm getting this error
undefined local variable or method `e' for ReactOnRails::ServerRenderingPool::Exec:Class
I've found on the shakacode site that there's a typo in lib/react_on_rails/server_rendering_pool/exec.rb
but I don't know how to access that file - it's nowhere in my directory - am I completely missing something here?
This has been fixed already on: https://github.com/shakacode/react_on_rails/pull/1020

Block Chain Ethereum Error NoMethodError: undefined method `keys' for nil:NilClass

I am integrating Block chain with my Rails App , so I am using Ethereum gem
to host the data to the blockchain.
I am getting the below error when i am trying to implement Ethereum to my Rails App.
I am using the following gem enter link description here
While i am trying the following command
init = Ethereum::Initializer.new("#{ENV['PWD']}/SimpleNameRegistry.sol", client)
I am getting the below error
NoMethodError: undefined method `keys' for nil:NilClass
when I try to debug inside the gem I received the following error code in the below line.
Error Line:
sol_output = #client.compile_solidity(#file)
Error Code:
{"jsonrpc"=>"2.0", "error"=>{"code"=>-32600, "message"=>"EOF"}}
Please help me to get out of this error as I am stuck with this.
Please also suggest me with an easy implementation of block chain with rails.

On production server at one page I am getting Fatal error ActionView::Template::Error

I am getting this error " ActionView::Template::Error (bad component(expected host component): ): ", on research on stackoverflow I observed this error is occurring on wrong config of mailer. But I have not configured any mails.
From the details shared , the first line indicates error in fetching the data.
A line of action to resolve this could be,
first to check the correctness of data fetch using rails console/sandbox environment.
Once point 1 above is sorted out and still error, then have a look at the view and check the rendering/flow.
This will point you to the error.

Get "Response code = 500" error randomly when running cucumber

For some reason I keep getting a response code of 500 when I run cucumber, even though all the tests pass. The error occurs randomly for different tests, every time I run it. Sometimes all tests pass as well.
I thought it was a memory issue, so I tried restarting my computer, but that didn't do anything.
An example of the error is:
And I follow "link" # features/step_definitions/web_steps.rb:33
Failed. Response code = 500. Response message = Internal Server Error. (ActiveResource::ServerError)
./app/controllers/companies_controller.rb:23:in `show'
./features/step_definitions/web_steps.rb:35
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:34:in `/^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/'
features/manage_sites.feature:256:in `And I follow "link"'
It seems related to the tagging feature. I was using the #wip tag, and when I moved it around, it would cause the sporadic 500 errors. Removing all #wip tags makes all the tests pass.
I could be wrong though. I'll need to try and replicate it consistently.
Would anybody be able to help?

Getting "undefined method `include?'" for request.user_agent

I've got this line of code:
if request.user_agent.include?("iPhone") then
But I'm occasionally getting this error:
"undefined method `include?' for nil:NilClass"
When checking logs on the error, there isn't a "HTTP_USER_AGENT" for the user that is getting the error.
So how can I fix that line so it doesn't throw an error if there isn't an HTTP_USER_AGENT?
For Rails 2.3.xx you can also use Object#try
request.user_agent.try(:include?, 'iphone')
Check here for more info.
Check it for nil or rescue the exception yourself.
NSD is right.
You could also use try as a short cut:
request.user_agent.try(:include?, "iPhone")
try will not error when its receiver is nil, so you can chain them together, like this:
foo.try(:bar).try(:baz)

Resources