Sha256: 822cf435bb097dc0e2f93c525d36a54a106cff2c4270a1f6e430820c61515cf8

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe Rack::OAuth2::Server::Authorize::Extension::IdTokenAndToken do
  subject { response }
  let(:request)      { Rack::MockRequest.new app }
  let(:response)     { request.get('/?response_type=token%20id_token&client_id=client&state=state') }
  let(:redirect_uri) { 'http://client.example.com/callback' }
  let(:bearer_token) { Rack::OAuth2::AccessToken::Bearer.new(:access_token => 'access_token') }
  let :id_token do
    OpenIDConnect::ResponseObject::IdToken.new(
      :iss => 'https://server.example.com',
      :user_id => 'user_id',
      :aud => 'client_id',
      :nonce => 'nonce',
      :exp => 1313424327
    ).to_jwt private_key
  end

  context 'when id_token is given' do
    let :app do
      Rack::OAuth2::Server::Authorize.new do |request, response|
        response.redirect_uri = redirect_uri
        response.access_token = bearer_token
        response.id_token = id_token
        response.approve!
      end
    end
    its(:status)   { should == 302 }
    its(:location) { should include "#{redirect_uri}#" }
    its(:location) { should include "access_token=#{bearer_token.access_token}" }
    its(:location) { should include "id_token=#{id_token}" }
    its(:location) { should include "token_type=#{bearer_token.token_type}" }
    its(:location) { should include 'state=state' }

    context 'when id_token is String' do
      let(:id_token) { 'id_token' }
      its(:location) { should include 'id_token=id_token' }
    end
  end

  context 'otherwise' do
    let :app do
      Rack::OAuth2::Server::Authorize.new do |request, response|
        response.redirect_uri = redirect_uri
        response.access_token = bearer_token
        response.approve!
      end
    end
    it do
      expect { response }.should raise_error AttrRequired::AttrMissing, "'id_token' required."
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
openid_connect-0.2.0 spec/rack/oauth2/server/authorize/extension/id_token_and_token_spec.rb
openid_connect-0.2.0.alpha3 spec/rack/oauth2/server/authorize/extension/id_token_and_token_spec.rb
openid_connect-0.2.0.alpha2 spec/rack/oauth2/server/authorize/extension/id_token_and_token_spec.rb
openid_connect-0.2.0.alpha spec/rack/oauth2/server/authorize/extension/id_token_and_token_spec.rb
openid_connect-0.1.5 spec/rack/oauth2/server/authorize/extension/id_token_and_token_spec.rb
openid_connect-0.1.4 spec/rack/oauth2/server/authorize/extension/id_token_and_token_spec.rb