Adjust protect resource endpoint spec
This commit is contained in:
parent
3cbe75469b
commit
cd2f1215e8
2 changed files with 9 additions and 22 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
class Api::V0::UsersController < Api::V0::BaseController
|
class Api::V0::UsersController < Api::V0::BaseController
|
||||||
before_filter do
|
before_action do
|
||||||
require_access_token OpenidConnect::Scope.find_by(name: "read")
|
require_access_token OpenidConnect::Scope.find_by(name: "read")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,30 @@
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
|
|
||||||
describe OpenidConnect::ProtectedResourceEndpoint, type: :request do
|
describe OpenidConnect::ProtectedResourceEndpoint, type: :request do
|
||||||
|
# TODO: Replace with factory
|
||||||
let!(:client) do
|
let!(:client) do
|
||||||
OpenidConnect::OAuthApplication.create!(
|
OpenidConnect::OAuthApplication.create!(
|
||||||
client_name: "Diaspora Test Client", redirect_uris: ["http://localhost:3000/"])
|
client_name: "Diaspora Test Client", redirect_uris: ["http://localhost:3000/"])
|
||||||
end
|
end
|
||||||
let(:auth_with_read) do
|
let(:auth_with_read) do
|
||||||
auth = OpenidConnect::Authorization.find_or_create_by(o_auth_application: client, user: bob)
|
auth = OpenidConnect::Authorization.create!(o_auth_application: client, user: alice)
|
||||||
auth.scopes << [OpenidConnect::Scope.find_or_create_by(name: "read")]
|
auth.scopes << [OpenidConnect::Scope.find_or_create_by(name: "read")]
|
||||||
auth
|
auth
|
||||||
end
|
end
|
||||||
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(:auth_with_read_and_write) do
|
|
||||||
auth = OpenidConnect::Authorization.find_or_create_by(o_auth_application: client, user: bob)
|
|
||||||
auth.scopes << [OpenidConnect::Scope.find_or_create_by(name: "read"), OpenidConnect::Scope.find_or_create_by(name: "write")]
|
|
||||||
auth
|
|
||||||
end
|
|
||||||
let!(:access_token_with_read_and_write) { auth_with_read_and_write.create_access_token.to_s }
|
|
||||||
let(:invalid_token) { SecureRandom.hex(32).to_s }
|
let(:invalid_token) { SecureRandom.hex(32).to_s }
|
||||||
|
|
||||||
# TODO: Add tests for expired access tokens
|
# TODO: Add tests for expired access tokens
|
||||||
|
|
||||||
context "when read scope access token is provided for read required endpoint" do
|
context "when valid access token is provided" do
|
||||||
describe "user info endpoint" do
|
|
||||||
before do
|
before do
|
||||||
get api_v0_user_path, access_token: access_token_with_read
|
get api_v0_user_path, access_token: access_token_with_read
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shows the info" do
|
|
||||||
json_body = JSON.parse(response.body)
|
|
||||||
expect(json_body["username"]).to eq(bob.username)
|
|
||||||
expect(json_body["email"]).to eq(bob.email)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "includes private in the cache-control header" do
|
it "includes private in the cache-control header" do
|
||||||
expect(response.headers["Cache-Control"]).to include("private")
|
expect(response.headers["Cache-Control"]).to include("private")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context "when no access token is provided" do
|
context "when no access token is provided" do
|
||||||
it "should respond with a 401 Unauthorized response" do
|
it "should respond with a 401 Unauthorized response" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue