mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-04-02 18:31:30 +08:00
Added access token to protocols.io requests [SCI-5968]
This commit is contained in:
parent
295d27f0d7
commit
1b26a4f65a
4 changed files with 6 additions and 26 deletions
.gitignore
app
services/protocol_importers
utilities/protocol_importers/protocols_io/v3
spec/utilities/protocol_importers/protocols_io/v3
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -35,6 +35,9 @@ ehthumbs.db
|
|||
# Ignore temporary files
|
||||
public/system/*
|
||||
|
||||
# Ignore BioEddie installion in public folder
|
||||
public/bio_eddie/
|
||||
|
||||
# Ignore ActiveStorage Disc service storage directory
|
||||
storage/
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ module ProtocolImporters
|
|||
@errors[:invalid_params][:page_id] = 'Page needs to be positive' if @query_params[:page_id]&.to_i&.negative?
|
||||
|
||||
# try if endpints exists
|
||||
@errors[:invalid_params][:source_endpoint] = 'Wrong source endpoint' unless endpoint_name&.is_a?(String)
|
||||
@errors[:invalid_params][:source_endpoint] = 'Wrong source endpoint' unless endpoint_name.is_a?(String)
|
||||
|
||||
succeed?
|
||||
end
|
||||
|
|
|
@ -12,12 +12,9 @@ module ProtocolImporters
|
|||
default_timeout CONSTANTS[:default_timeout]
|
||||
logger Rails.logger, CONSTANTS[:debug_level]
|
||||
|
||||
def initialize(token = nil)
|
||||
# Currently we support public tokens only (no token needed for public data)
|
||||
@auth = { token: token }
|
||||
|
||||
def initialize
|
||||
# Set default headers
|
||||
self.class.headers('Authorization': "Bearer #{@auth[:token]}") if @auth[:token].present?
|
||||
self.class.headers('Authorization' => "Bearer #{ENV.fetch('PROTOCOLS_IO_ACCESS_TOKEN')}")
|
||||
end
|
||||
|
||||
# Query params available are:
|
||||
|
|
|
@ -4,7 +4,6 @@ require 'rails_helper'
|
|||
|
||||
describe ProtocolImporters::ProtocolsIo::V3::ApiClient do
|
||||
CONSTANTS = Constants::PROTOCOLS_IO_V3_API
|
||||
TOKEN = 'test_token'
|
||||
|
||||
describe '#protocol_list' do
|
||||
context 'when search key is not given' do
|
||||
|
@ -114,17 +113,6 @@ describe ProtocolImporters::ProtocolsIo::V3::ApiClient do
|
|||
subject.protocol_list(query)
|
||||
expect(WebMock).to have_requested(:get, URL).with(query: query)
|
||||
end
|
||||
|
||||
it 'should send authorization token if provided on initialization' do
|
||||
headers = { 'Authorization': "Bearer #{TOKEN}" }
|
||||
stub_protocols.with(headers: headers, query: default_query_params_with_key)
|
||||
.to_return(status: 200,
|
||||
body: JSON.generate(status_code: 0),
|
||||
headers: { 'Content-Type': 'application/json' })
|
||||
|
||||
ProtocolImporters::ProtocolsIo::V3::ApiClient.new(TOKEN).protocol_list(key_query)
|
||||
expect(WebMock).to have_requested(:get, URL).with(headers: headers, query: default_query_params_with_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -152,14 +140,6 @@ describe ProtocolImporters::ProtocolsIo::V3::ApiClient do
|
|||
|
||||
expect { subject.single_protocol(PROTOCOL_ID) }.to raise_error(ProtocolImporters::ProtocolsIo::V3::NetworkError)
|
||||
end
|
||||
|
||||
it 'should send authorization token if provided on initialization' do
|
||||
headers = { 'Authorization': "Bearer #{TOKEN}" }
|
||||
stub_single_protocol.with(headers: headers)
|
||||
|
||||
ProtocolImporters::ProtocolsIo::V3::ApiClient.new(TOKEN).single_protocol(PROTOCOL_ID)
|
||||
expect(WebMock).to have_requested(:get, SINGLE_PROTOCOL_URL).with(headers: headers)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#protocol_html_preview' do
|
||||
|
|
Loading…
Add table
Reference in a new issue