Sha256: affaf83bbf7c0966e7272c6d8d24bd791cf33b3464958c78c634ac085d1e7a8b

Contents?: true

Size: 1.78 KB

Versions: 16

Compression:

Stored size: 1.78 KB

Contents

require 'test_helper'

module Workarea
  module Api
    module Admin
      class AuthenticationIntegrationTest < IntegrationTest
        def encode_credentials(*args)
          ActionController::HttpAuthentication::Basic.encode_credentials(*args)
        end

        def test_requires_basic_authentication
          get admin_api.products_path
          assert_equal(401, response.status)
        end

        def test_only_allows_admin_users_with_api_access
          user = create_user(admin: false, password: 'Ap1_test')
          admin = create_user(admin: true, password: 'Ap1_test')
          admin_with_api = create_user(
            admin: true,
            password: 'Ap1_test',
            api_access: true
          )

          get admin_api.products_path,
            headers: {
              'HTTP_AUTHORIZATION' => encode_credentials(user.email, 'Ap1_test')
            }
          assert_equal(401, response.status)

          get admin_api.products_path,
            headers: {
              'HTTP_AUTHORIZATION' => encode_credentials(admin.email, 'Ap1_test')
            }
          assert_equal(401, response.status)

          get admin_api.products_path,
            headers: {
              'HTTP_AUTHORIZATION' => encode_credentials(admin_with_api.email, 'Ap1_test')
            }
          assert_equal(200, response.status)
        end

        def test_allows_super_admins
          super_admin = create_user(
            admin: false,
            super_admin: true,
            api_access: false,
            password: 'Ap1_test'
          )

          get admin_api.products_path,
            headers: {
              'HTTP_AUTHORIZATION' => encode_credentials(super_admin.email, 'Ap1_test')
            }
          assert_equal(200, response.status)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
workarea-api-4.5.6 admin/test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-admin-4.5.6 test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-4.5.5 admin/test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-admin-4.5.5 test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-4.5.4 admin/test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-admin-4.5.4 test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-4.5.3 admin/test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-admin-4.5.3 test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-4.5.2 admin/test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-admin-4.5.2 test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-4.5.0 admin/test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-admin-4.5.0 test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-4.4.7 admin/test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-admin-4.4.7 test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-4.4.6 admin/test/integration/workarea/api/admin/authentication_integration_test.rb
workarea-api-admin-4.4.6 test/integration/workarea/api/admin/authentication_integration_test.rb