Sha256: cf091b2482e764c372a699958ff7cc42aa9b0c6f687e6fd28c94a6f5fc1380ec

Contents?: true

Size: 1.75 KB

Versions: 14

Compression:

Stored size: 1.75 KB

Contents

## NOT CAPYBARA
#  ActionDispatch::IntegrationTest
#  http://guides.rubyonrails.org/testing.html#integration-testing
#  used so we can test POST actions ^_^

require 'test_helper'

class RefreshTokenTest < ActionDispatch::IntegrationTest
  setup do
    Timecop.freeze(Time.now)
    Opro.setup do |config|
      config.require_refresh_within = 1.month
    end

    @user         = create_user
    @auth_grant   = create_auth_grant_for_user(@user)
    @client_app   = @auth_grant.application
  end

  teardown do
    Timecop.return # "turn off" Timecop
  end

  test "clients get a valid refresh token" do
    params = {:client_id      => @client_app.client_id ,
              :client_secret  => @client_app.client_secret,
              :code           => @auth_grant.code}
    as_user(@user).post oauth_token_path(params)
    json_hash = JSON.parse(response.body)
    assert_equal json_hash['expires_in'], @auth_grant.expires_in
  end

  test "exchange a refresh_token for an access_token" do
    params = {:client_id      => @client_app.client_id ,
              :client_secret  => @client_app.client_secret,
              :refresh_token  => @auth_grant.refresh_token}

    Timecop.travel(2.days.from_now)

    as_user(@user).post oauth_token_path(params)

    json_hash = JSON.parse(response.body)
    refute_equal json_hash['access_token'],   @auth_grant.access_token
    refute_equal json_hash['refresh_token'],  @auth_grant.refresh_token
    refute_equal json_hash['expires_in'],     @auth_grant.expires_in


    auth_grant = Opro::Oauth::AuthGrant.find(@auth_grant.id)
    assert_equal json_hash['access_token'],   auth_grant.access_token
    assert_equal json_hash['refresh_token'],  auth_grant.refresh_token
    assert_equal json_hash['expires_in'],     auth_grant.expires_in
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
opro-0.4.2 test/integration/action_dispatch/refresh_token_test.rb
opro-0.4.1 test/integration/action_dispatch/refresh_token_test.rb
opro-0.4.0 test/integration/action_dispatch/refresh_token_test.rb
opro-0.3.3 test/integration/action_dispatch/refresh_token_test.rb
opro-0.3.2 test/integration/action_dispatch/refresh_token_test.rb
opro-0.3.1 test/integration/action_dispatch/refresh_token_test.rb
opro-0.3.0 test/integration/action_dispatch/refresh_token_test.rb
opro-0.3.0.pre3 test/integration/action_dispatch/refresh_token_test.rb
opro-0.3.0.pre2 test/integration/action_dispatch/refresh_token_test.rb
opro-0.3.0.pre1 test/integration/action_dispatch/refresh_token_test.rb
opro-0.3.0.pre test/integration/action_dispatch/refresh_token_test.rb
opro-0.2.1.pre test/integration/action_dispatch/refresh_token_test.rb
opro-0.2.0 test/integration/action_dispatch/refresh_token_test.rb
opro-0.1.0 test/integration/action_dispatch/refresh_token_test.rb