Sha256: 3288ea8c8e92fb25b1c3615f354421a4d946267709444e4698243407161400d7

Contents?: true

Size: 1.64 KB

Versions: 8

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

describe Rack::OAuth2::Server::Authorize::Extension::CodeAndIdToken do
  subject { response }
  let(:request)      { Rack::MockRequest.new app }
  let(:response)     { request.get("/?response_type=code%20id_token&client_id=client&state=state") }
  let(:redirect_uri) { 'http://client.example.com/callback' }
  let(:code)         { 'authorization_code' }
  let :id_token do
    OpenIDConnect::ResponseObject::IdToken.new(
      iss: 'https://server.example.com',
      user_id: 'user_id',
      aud: 'client_id',
      nonce: 'nonce',
      exp: 1313424327,
      iat: 1313420327
    ).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.code = code
        response.id_token = id_token
        response.approve!
      end
    end
    its(:status)   { should == 302 }
    its(:location) { should include "#{redirect_uri}#" }
    its(:location) { should include "code=#{code}" }
    its(:location) { should include "id_token=#{id_token}" }
    its(:location) { should include "state=state" }

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
openid_connect-0.5.1 spec/rack/oauth2/server/authorize/extension/code_and_id_token_spec.rb
openid_connect-0.5.0 spec/rack/oauth2/server/authorize/extension/code_and_id_token_spec.rb
openid_connect-0.4.1 spec/rack/oauth2/server/authorize/extension/code_and_id_token_spec.rb
openid_connect-0.4.0 spec/rack/oauth2/server/authorize/extension/code_and_id_token_spec.rb
openid_connect-0.3.7 spec/rack/oauth2/server/authorize/extension/code_and_id_token_spec.rb
openid_connect-0.3.6 spec/rack/oauth2/server/authorize/extension/code_and_id_token_spec.rb
openid_connect-0.3.5 spec/rack/oauth2/server/authorize/extension/code_and_id_token_spec.rb
openid_connect-0.3.4 spec/rack/oauth2/server/authorize/extension/code_and_id_token_spec.rb