Encoding Error when using Devise ldap authentication - ruby-on-rails

I have been scouring the Internet for an answer to this but I'm out of ideas. I am using Devise with Rails 3 to authenticate with LDAP. I'm using Rails 3 with Ruby 1.9.2. I'm using mysql2 as the database connector.
I can get this to work with the rails console so I know my addresses and everything are correct.
We have an active directory and in order to authenticate we have to prefix the login name with systems. So my login would be systems\crudbasher.
This works in the console but when I have a form with login name and password I get this error.
Encoding::CompatibilityError in Devise::SessionsController#create
incompatible character encodings: ASCII-8BIT and UTF-8
Ok I get that it is having a problem with the backslash. What I don't understand is how to fix it.
The full stack trace if it helps is this:
net-ldap (0.2.2) lib/net/ber/core_ext/array.rb:62:in `to_ber_seq_internal'
net-ldap (0.2.2) lib/net/ber/core_ext/array.rb:54:in `to_ber_contextspecific'
net-ldap (0.2.2) lib/net/ldap/filter.rb:509:in `to_ber'
net-ldap (0.2.2) lib/net/ldap.rb:1380:in `block in search'
net-ldap (0.2.2) lib/net/ldap.rb:1361:in `loop'
net-ldap (0.2.2) lib/net/ldap.rb:1361:in `search'
net-ldap (0.2.2) lib/net/ldap.rb:635:in `search'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:208:in `search_for_login'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:86:in `dn'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:124:in `authorized?'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:14:in `valid_credentials?'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/model.rb:39:in `valid_ldap_authentication?'
activesupport (3.1.1) lib/active_support/core_ext/object/try.rb:32:in `try'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/model.rb:85:in `authenticate_with_ldap'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/strategy.rb:12:in `authenticate!'
I'm really stumped. Thank you to anyone who can help!!

Encoding is always a mess. Have you tried toying around with encode and force_encoding?

I had this same problem and I fixed by updating net-ldap library to 0.3.1, but that broke mine get_ldap_email (which is just like devise_ldap_authenticatable main page example, Querying LDAP)
Also everything seemed to be ok but I'm not 100% sure if nothing else is broken.
Edit: Apparently I also need to update devise_ldap_authenticatable to version 0.4.7 or higher -> Ruby on Rails 3: Devise::LdapAdapter.get_ldap_param undefined method error
But I'm not sure how to update both, devise_ldap and net-ldap, and not breaking my bundle update

Related

Rails not using modified gem instead of original

this is what I believe a simple problem I need help with. I'm trying to modify a gem's method so that I can add another argument to it. For this, I've cloned the gem's repo to a local directory and changed the code I needed. Inside my app's Gemfile I'm doing this:
gem 'recommendable', path: "/home/aristizabal95/forked_gems/recommendable"
And running bundle install afterwards. Even though the bundler says it's using my code, when I run the tests I get this error:
ArgumentError: wrong number of arguments (given 4, expected 1..3)
from /var/lib/gems/2.3.0/gems/recommendable-2.2.0/lib/recommendable/rater/recommender.rb:21:in `recommended_for'
which indicates that the app is not running my version of the gem, but the original one. I have no idea why it's not working, and was unable to find any issue related to this.
Thanks in advance
EDIT:
This is what the Gemfile.lock looks like
PATH
remote: /home/aristizabal95/forked_gems/recommendable
specs:
recommendable (2.2.1)
activesupport (>= 3.0.0)
hooks (>= 0.2.1)
redis (>= 2.2.0)
GEM
recommendable!
My guess is that spring still has the gem from the original gem source loaded.
To force spring to reload the gem (from your local source), do:
spring stop
in the console. Then restart your server and you should be using the gem from your local source.

No Keyboard Output from Guard

When entering into debugger (byebug) with guard-minitest, I am unable to see the output while I am typing. I have seen this problem with Rails 4.2.8 as well as Rails 5.
If I run the test outside of guard, the debugger works fine.
byebug (9.0.6)
guard (2.14.1)
guard-minitest (2.4.6)
rails (4.2.8)
do you have rb-readline gem installed?
In my case removing it from Gemfile solved this issue!

Why does Rails / ActiveRecord gives a Postgres SyntaxError "non-integer constant in ORDER"?

I have some Ruby on Rails / ActiveRecord code that is giving me the following Postgres error:
PG::SyntaxError: ERROR: non-integer constant in ORDER
I'm not sure why since it is a simple fetch ordered by created_at
self.posts.order(created_at: :desc).limit(25)
What do I do to change this?
I am not sure that syntax is supported in older versions of Rails, which is where I suspect you are. Try this instead:
self.posts.order("created_at desc").limit(25)
I have experienced this error as well after switching my Rails app from MySQL to PostgreSQL (my development environment and Gem list are at the bottom of this post).
The error appears to be caused by PostgreSQL expecting the column names in a SQL query to be double-quoted, as I am able to eliminate the error by changing my ".order()" parameter from hash-format to a literal string:
This Rails code triggers the error:
ModelName.where(:attribute => self.id).order(col1: :desc, col2: :asc)
...and the resulting error:
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
ModelName Load (1.0ms) SELECT "model_name".* FROM "model_name" WHERE ("model_name"."attribute" = 14) ORDER BY '{:col1=>:desc, :col2=>:asc}'
PG::SyntaxError: ERROR: non-integer constant in ORDER BY
LINE 1: ...E ("model_name"."attribute" = 14) ORDER BY '{:col1=...
^
Whereas this Rails code works without triggering the error message:
ModelName.where(:attribute => self.id).order("\"col1\" desc, \"col2\" asc")
I know that PostgreSQL is able to correctly interpret non-quoted identifiers, but the format of the query that ActiveRecord generates in this case appears to be ambiguous to Postgresql. Here's a description of PostgreSQL query syntax: http://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html
Here's my development environment:
Windows 7
Ruby 2.1.5p273
Rails 3.0.3 (I know it's old...)
PostgreSQL 9.4 (on windows)
...and here's the pertinent part of my gem list:
*** LOCAL GEMS ***
abstract (1.0.0)
afm (0.2.2)
arel (2.0.10)
builder (2.1.2)
bundler (1.7.7)
hashery (2.1.1)
i18n (0.6.11)
mysql (2.9.1)
pg (0.18.1 x86-mingw32)
rack (1.2.8)
rails (3.0.3)
railties (3.0.3)
rake (0.9.2.2)
ruby-rc4 (0.1.5)
sequel (3.31.0)
valkyrie (0.0.2)

Sunspot_rails isn't respecting :auto_index and :auto_remove

I'm trying to make our application more resilient to downtime from our search server. To achieve this, I'm trying to disable the automatic indexing and removal, and manual perform them in a background process.
I'm trying
searchable :auto_index => false, :auto_remove => false do
...
end
But am still receiving a connection error, every time I try to save or destroy the record.
The backtrace shows that the error is coming from the solr searchable file, so it's definetly sunspot_rails causing the problem. Here is a slice from the backtrace on destroy:
...
rsolr (1.0.8) lib/rsolr/client.rb:67:in `update'
rsolr (1.0.8) lib/rsolr/client.rb:121:in `delete_by_id'
sunspot (1.3.3) lib/sunspot/indexer.rb:36:in `remove'
sunspot (1.3.3) lib/sunspot/session.rb:137:in `block in remove'
sunspot (1.3.3) lib/sunspot/session.rb:136:in `each'
sunspot (1.3.3) lib/sunspot/session.rb:136:in `remove'
sunspot (1.3.3) lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `remove'
sunspot (1.3.3) lib/sunspot.rb:410:in `remove'
sunspot_rails (1.3.3) lib/sunspot/rails/searchable.rb:390:in `solr_remove_from_index'
sunspot_rails (1.3.3) lib/sunspot/rails/searchable.rb:93:in `block in searchable'
...
Any idea why the options to disable these hooks aren't working? Any idea how to actually disable them?
Thanks
Found the answer to my own question:
Turns out that while automatic callbacks were disabled, I was still making it dirty in a different step. sunspot_rails has a cleanup step that runs at the end of a request and tries to commit all dirty records to the solr server. To disable it add auto_commit_after_request: false to your sunspot.yml.

Error running Heckle? `current_code': undefined method `translate' for Ruby2Ruby

I'm trying to run Heckle, and I keep getting an error:
> spec spec/controllers/my_controller_spec.rb --heckle MyController
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! exception= has a thick skin. There's nothing to heckle.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
(Runs through several mutations...)
/home/developer/.gem/ruby/1.8/gems/heckle-1.4.3/lib/heckle.rb:603:in `current_code': undefined method `translate' for Ruby2Ruby:Class (NoMethodError)
Any thoughts?
EDIT: I forgot the gem versions:
heckle (1.4.3)
ruby2ruby (1.2.3)
rails (2.3.2, 2.2.2)
rspec (1.2.6)
rspec-rails(1.2.6, 1.1.12)
Install ruby2ruby 1.2.2. There seems to be an API change in 1.2.3.
Just generated the docs for 1.2.2 and 1.2.3
Looks like the class method 'translate' has been totally removed, although the docs don't reflect this

Resources