Sha256: 7b713e9ee317553e0946d79a997e75b86ff05d223083b29893abd727dacda9a5

Contents?: true

Size: 1.91 KB

Versions: 5

Compression:

Stored size: 1.91 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 AuthControllerTest < ActionDispatch::IntegrationTest
  setup do
    @user         = create_user
    @client_app   = create_client_app
    @redirect_uri = '/'
  end


  test "AUTHORIZE: previously authed user gets Authed immediately, permissions not changed" do
    auth_grant  = create_auth_grant_for_user(@user, @client_app)

    params = { :client_id     => @client_app.client_id ,
               :client_secret => @client_app.client_secret,
               :redirect_uri  => @redirect_uri }

    as_user(@user).post oauth_authorize_path(params)

    assert_equal 302, status
    follow_redirect!
    assert_equal @redirect_uri, path
  end


  test "AUTHORIZE: app cannot force permissions change for previously authed user" do
    auth_grant  = create_auth_grant_for_user(@user, @client_app)
    permissions = { 'foo' => 1 }
    assert_not_equal auth_grant.permissions, permissions

    params = { :client_id     => @client_app.client_id ,
               :client_secret => @client_app.client_secret,
               :redirect_uri  => @redirect_uri,
               :permissions   => permissions }

    as_user(@user).post oauth_authorize_path(params)

    assert_equal 302, status
    follow_redirect!
    assert_equal @redirect_uri, path
    auth_grant = Opro::Oauth::AuthGrant.find(auth_grant.id)

    refute auth_grant.permissions.has_key?(permissions.keys.first)
  end


  test "AUTHORIZE: user gets redirected to new form if not already authed" do
    params = { :client_id     => @client_app.client_id ,
               :client_secret => @client_app.client_secret,
               :redirect_uri  => @redirect_uri }

    as_user(@user).post oauth_authorize_path(params)

    assert_equal 302, status
    follow_redirect!
    assert_equal oauth_new_path, path
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opro-0.3.0.pre1 test/integration/action_dispatch/auth_controller_test.rb
opro-0.3.0.pre test/integration/action_dispatch/auth_controller_test.rb
opro-0.2.1.pre test/integration/action_dispatch/auth_controller_test.rb
opro-0.2.0 test/integration/action_dispatch/auth_controller_test.rb
opro-0.1.0 test/integration/action_dispatch/auth_controller_test.rb