Sha256: f37e1504fae3efa43c2f431a8deef1b636bf60dbc015e82a85fcfdddbe033527

Contents?: true

Size: 1.72 KB

Versions: 7

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 400 }
  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 400 }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
devise-doorkeeper-1.1.2.ci.123.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2.ci.118.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2.ci.112.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2.ci.103.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2.ci.96.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2.ci.89.1 spec/requests/oauth/password_grant_spec.rb
devise-doorkeeper-1.1.2.ci.62.1 spec/requests/oauth/password_grant_spec.rb