fix(graphql): check if tokens are revoked
This commit is contained in:
parent
286db17eb2
commit
ee30a95847
2 changed files with 29 additions and 1 deletions
|
@ -10,7 +10,7 @@ class API::V2::BaseController < ApplicationController
|
|||
def context
|
||||
# new token give administrateur_id
|
||||
if api_token.administrateur?
|
||||
{ administrateur_id: api_token.administrateur_id }
|
||||
{ administrateur_id: api_token.administrateur_id, token: api_token.token }
|
||||
# web interface (/graphql) give current_administrateur
|
||||
elsif current_administrateur.present?
|
||||
{ administrateur_id: current_administrateur.id }
|
||||
|
|
|
@ -123,6 +123,34 @@ describe API::V2::GraphqlController do
|
|||
request.env['HTTP_AUTHORIZATION'] = authorization_header
|
||||
end
|
||||
|
||||
describe "token authentication" do
|
||||
it {
|
||||
expect(gql_errors).to eq(nil)
|
||||
expect(gql_data).not_to be_nil
|
||||
}
|
||||
|
||||
context "when the token is invalid" do
|
||||
before do
|
||||
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials('invalid')
|
||||
end
|
||||
|
||||
it {
|
||||
expect(gql_errors.first[:message]).to eq("An object of type Demarche was hidden due to permissions")
|
||||
}
|
||||
end
|
||||
|
||||
context "when the token is revoked" do
|
||||
before do
|
||||
admin.update(encrypted_token: nil)
|
||||
end
|
||||
|
||||
it {
|
||||
expect(token).not_to be_nil
|
||||
expect(gql_errors.first[:message]).to eq("An object of type Demarche was hidden due to permissions")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "demarche" do
|
||||
describe "query a demarche" do
|
||||
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, :with_all_champs, :with_all_annotations, administrateurs: [admin]) }
|
||||
|
|
Loading…
Reference in a new issue