timwaters / omniauth-mediawiki

MediaWiki OAuth strategy for Omniauth, used for all wikimedia.org wikis (e.g. commons.wikimedia.org , wikipedia.org) with the oauth extension installed
Other
4 stars 9 forks source link

OmniAuth.config.test_mode = true does not allow login in integration tests #2

Closed ragesoss closed 8 years ago

ragesoss commented 8 years ago

Hi! First off, thanks for this gem, which I've found very useful in my project.

I've tried several times to get an integration test working with MediaWiki login, but I always get stuck.

With OmniAuth.config.test_mode = true, the login path errors like this:

     ActionController::RoutingError:
       No route matches [GET] "/users/auth/oob"

Any ideas on how to get the full login process working in an integration test?

ragesoss commented 8 years ago

I was able to make it work like so:


      OmniAuth.config.test_mode = true
      allow_any_instance_of(OmniAuth::Strategies::Mediawiki)
        .to receive(:callback_url).and_return('/users/auth/mediawiki/callback')
      OmniAuth.config.mock_auth[:mediawiki] = OmniAuth::AuthHash.new(
        provider: 'mediawiki',
        uid: '12345',
        info: { name: 'Ragesock' },
        credentials: { token: 'foo', secret: 'bar' }
      )

Here it is in context: https://github.com/WikiEducationFoundation/WikiEduDashboard/commit/599629cd8616c2bea501f60750bb9e815b962829

timwaters commented 8 years ago

:smile:

Awesome, many thanks! glad it worked. I'll try to add it to the readme soon, I've also some better examples of how to use the gem to call the API which I want to add to the readme (see https://github.com/timwaters/mediawiki-oauth-api-hack for my scratch pad at this)