o_auth_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. require 'rails_helper'
  2. RSpec.describe 'OAuth', type: :request do
  3. describe 'request handling' do
  4. it 'does o365 - start' do
  5. post '/auth/microsoft_office365'
  6. expect(response).to have_http_status(:found)
  7. expect(response.body).to include('https://login.microsoftonline.com/common/oauth2/v2.0/authorize')
  8. expect(response.body).to include('redirect_uri=http%3A%2F%2Fzammad.example.com%2Fauth%2Fmicrosoft_office365%2Fcallback')
  9. expect(response.body).to include('scope=openid+email+profile')
  10. expect(response.body).to include('response_type=code')
  11. end
  12. it 'does o365 - callback' do
  13. get '/auth/microsoft_office365/callback?code=1234&state=1234'
  14. expect(response).to have_http_status(:found)
  15. expect(response.body).to include('302 Moved')
  16. end
  17. it 'does auth failure' do
  18. get '/auth/failure?message=123&strategy=some_provider'
  19. expect(response).to have_http_status(:unprocessable_entity)
  20. expect(response.body).to include('<title>422: Unprocessable Entity</title>')
  21. expect(response.body).to include('<h1>422: The change you wanted was rejected.</h1>')
  22. expect(response.body).to include('<div>Message from some_provider: 123</div>')
  23. end
  24. end
  25. end