o_auth_spec.rb 1.3 KB

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