twitter / twurl

OAuth-enabled curl for the Twitter API
https://developer.twitter.com
MIT License
1.8k stars 302 forks source link

`expand_path': couldn't find login name -- expanding `~' (ArgumentError) #142

Closed edipoReboucas closed 4 years ago

edipoReboucas commented 4 years ago

I'm trying use Support authorization options on request

When I run with a user without $HOME directory, in the case www-data (apache user), I'm getting the error:

/var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/rcfile.rb:6:in `expand_path': couldn't find login name -- expanding `~' (ArgumentError)
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/rcfile.rb:6:in `directory'
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/rcfile.rb:14:in `file_path'
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/rcfile.rb:18:in `load'
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/rcfile.rb:30:in `initialize'
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/oauth_client.rb:6:in `new'
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/oauth_client.rb:6:in `rcfile'
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/oauth_client.rb:12:in `load_from_options'
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/cli.rb:25:in `dispatch'
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/lib/twurl/cli.rb:21:in `run'
    from /var/lib/gems/2.5.0/gems/twurl-0.9.5/bin/twurl:4:in `<top (required)>'
    from /usr/local/bin/twurl:23:in `load'
    from /usr/local/bin/twurl:23:in `<main>'

I belive that is correlated this bug in another ruby project.

# fixes: couldn't find login name expanding tilde (cont.)

As workaround, I change RCFile class

module Twurl
  class RCFile
    FILE = '.twurlrc'
    class << self
      def directory
        @@directory ||= '' 
        #@@directory ||= File.expand_path('~')

Expected behavior

Send request without .twurlrc file

Actual behavior

twurl crash and print a error message

Steps to reproduce the behavior

smaeda-ks commented 4 years ago

@edipoReboucas Thanks. For me, the proper fix is to rewrite this logic: https://github.com/twitter/twurl/blob/master/lib/twurl/oauth_client.rb#L12-L26

there are too many if conditions and it should be simplified. I'll look into this and open a PR later.