Sha256: e8a3a268db7a9f9584758b0f8a3f44b41456fe3346c5578885f7be6f6be71625

Contents?: true

Size: 1.72 KB

Versions: 10

Compression:

Stored size: 1.72 KB

Contents

require 'rails_helper'

RSpec.describe 'oauth/tokens password grant flow', type: :request do
  context 'with valid username/password' do
    with :user
    with :application
    let(:params) do
      {
        client_id: application.uid,
        client_secret: application.secret,
        username: user.email,
        password: user.password,
        grant_type: 'password'
      }
    end
    let(:headers) { {} }
    let(:expected_response) do
      {
        access_token: @new_token.token,
        token_type: 'bearer',
        expires_in: 'ignored',
        created_at: 'ignored'
      }.to_json
    end
    before do
      post '/oauth/token', params, headers
      @new_token = Doorkeeper::AccessToken.last
    end
    it { expect(response.status).to eq 200 }
    it { expect(response.body).to be_json_eql(expected_response).excluding('expires_in', 'created_at') }
  end
  context 'with invalid password' do
    with :user
    with :application
    let(:params) do
      {
        client_id: application.uid,
        client_secret: application.secret,
        username: user.email,
        password: 'invalid password',
        grant_type: 'password'
      }
    end
    let(:headers) { {} }
    before do
      post '/oauth/token', params, headers
    end
    it { expect(response.status).to eq 401 }
  end
  context 'with invalid username' do
    with :user
    with :application
    let(:params) do
      {
        client_id: application.uid,
        client_secret: application.secret,
        username: 'invalid username',
        password: 'invalid password',
        grant_type: 'password'
      }
    end
    let(:headers) { {} }
    before do
      post '/oauth/token', params, headers
    end
    it { expect(response.status).to eq 401 }
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
devise-doorkeeper-1.1.2.ci.59.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2.ci.45.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2.ci.33.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2.ci.30.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.1.ci.22.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.0 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.0.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.0.0 spec/requests/oauth/password_grant_spec.rb