Add test for expired access token

This commit is contained in:
theworldbright 2015-08-02 13:52:09 +09:00
parent 6e1a673459
commit 98fd18077a
3 changed files with 19 additions and 6 deletions

View file

@ -57,7 +57,6 @@ module Api
auth.code = nil if auth # Remove auth code if found so it can't be reused auth.code = nil if auth # Remove auth code if found so it can't be reused
auth auth
end end
# TODO: Consider splitting into subclasses by flow type
end end
end end
end end

View file

@ -50,8 +50,6 @@ module Api
end end
} }
end end
# TODO: buildResponseType(req)
end end
end end
end end

View file

@ -1,12 +1,15 @@
require "spec_helper" require "spec_helper"
describe Api::OpenidConnect::ProtectedResourceEndpoint, type: :request do describe Api::OpenidConnect::ProtectedResourceEndpoint, type: :request do
let(:auth_with_read) { FactoryGirl.create(:auth_with_read) } let(:auth_with_read) { FactoryGirl.create(:auth_with_read) }
let!(:access_token_with_read) { auth_with_read.create_access_token.to_s } let!(:access_token_with_read) { auth_with_read.create_access_token.to_s }
let!(:expired_access_token) do
access_token = auth_with_read.o_auth_access_tokens.create!
access_token.expires_at = Time.zone.now - 100
access_token.save
access_token.bearer_token.to_s
end
let(:invalid_token) { SecureRandom.hex(32).to_s } let(:invalid_token) { SecureRandom.hex(32).to_s }
# TODO: Add tests for expired access tokens
context "when valid access token is provided" do context "when valid access token is provided" do
before do before do
get api_openid_connect_user_info_path, access_token: access_token_with_read get api_openid_connect_user_info_path, access_token: access_token_with_read
@ -17,6 +20,19 @@ describe Api::OpenidConnect::ProtectedResourceEndpoint, type: :request do
end end
end end
context "when access token is expired" do
before do
get api_openid_connect_user_info_path, access_token: expired_access_token
end
it "should respond with a 401 Unauthorized response" do
expect(response.status).to be(401)
end
it "should have an auth-scheme value of Bearer" do
expect(response.headers["WWW-Authenticate"]).to include("Bearer")
end
end
context "when no access token is provided" do context "when no access token is provided" do
before do before do
get api_openid_connect_user_info_path get api_openid_connect_user_info_path