1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Oauth::DeviceAuthorizationsController, feature_category: :system_access do
let(:user) { create(:user) }
before do
sign_in(user)
end
describe "GET #index" do
render_views
context "when requested with HTML format" do
it "renders the 'doorkeeper/device_authorization_grant/index' template" do
get :index, format: :html
expect(response).to render_template("doorkeeper/device_authorization_grant/index")
expect(response).to have_gitlab_http_status(:ok)
end
it "uses the 'minimal' layout" do
get :index, format: :html
expect(response).to render_template(layout: 'minimal')
end
end
context "when requested with JSON format" do
it "returns a no content status" do
get :index, format: :json
expect(response).to have_gitlab_http_status(:no_content)
end
end
end
describe 'POST #confirm' do
let(:user_code) { 'valid_user_code' }
let(:device_grant) { instance_double('Doorkeeper::DeviceAuthorizationGrant::DeviceGrant', scopes: 'read write') }
let(:invalid_user_code) { 'invalid_user_code' }
before do
allow(controller).to receive(:device_grant_model).and_return(Doorkeeper::DeviceAuthorizationGrant::DeviceGrant)
end
context 'with valid user_code' do
before do
allow(Doorkeeper::DeviceAuthorizationGrant::DeviceGrant).to receive(:find_by)
.with(user_code: user_code).and_return(device_grant)
end
it 'assigns @scopes' do
post :confirm, params: { user_code: user_code }, format: :html
expect(assigns(:scopes)).to eq('read write')
end
it 'renders the authorize template' do
post :confirm, params: { user_code: user_code }, format: :html
expect(response).to render_template('doorkeeper/device_authorization_grant/authorize')
end
it 'responds with no content for JSON format' do
post :confirm, params: { user_code: user_code }, format: :json
expect(response).to have_gitlab_http_status(:no_content)
end
end
context 'with invalid user_code' do
before do
allow(Doorkeeper::DeviceAuthorizationGrant::DeviceGrant).to receive(:find_by)
.with(user_code: invalid_user_code).and_return(nil)
end
it 'assigns @scopes as an empty string' do
post :confirm, params: { user_code: invalid_user_code }, format: :html
expect(assigns(:scopes)).to eq('')
end
it 'renders the authorize template' do
post :confirm, params: { user_code: invalid_user_code }, format: :html
expect(response).to render_template('doorkeeper/device_authorization_grant/authorize')
end
it 'responds with no content for JSON format' do
post :confirm, params: { user_code: invalid_user_code }, format: :json
expect(response).to have_gitlab_http_status(:no_content)
end
end
end
end
|