Fix linkedin initialization
closes CNVS-21340 this initializer was producing the right keys, but not with indifferent access, so string access wasn't working and the linkedin registered service would just die. Also fixed a problem in the twitter connector which has the same issue with running a find at initialization time. TEST PLAN: 1) linked in as a registered service should not break horribly 2) twitter as a registered service should not break horribly Change-Id: Iaa3a5c7f3f0ac5561079a334493d215399d45d76 Reviewed-on: https://gerrit.instructure.com/57186 Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: August Thornton <august@instructure.com> Product-Review: Ethan Vizitei <evizitei@instructure.com> Tested-by: Jenkins
This commit is contained in:
parent
aa349e812a
commit
c6887533fe
|
@ -1,11 +1,17 @@
|
|||
LinkedIn::Connection.config = Proc.new do
|
||||
class CanvasLinkedInConfig
|
||||
|
||||
def self.call
|
||||
settings = Canvas::Plugin.find(:linked_in).try(:settings)
|
||||
if settings
|
||||
{
|
||||
api_key: settings[:client_id],
|
||||
secret_key: settings[:client_secret_dec]
|
||||
}
|
||||
}.with_indifferent_access
|
||||
else
|
||||
ConfigFile.load('linked_in')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
LinkedIn::Connection.config = CanvasLinkedInConfig
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
class CanvasTwitterConfig
|
||||
def initialize(plugin=Canvas::Plugin.find(:twitter))
|
||||
@plugin = plugin
|
||||
end
|
||||
|
||||
def call
|
||||
settings = @plugin.try(:settings)
|
||||
def self.call
|
||||
settings = Canvas::Plugin.find(:twitter).try(:settings)
|
||||
if settings
|
||||
{
|
||||
api_key: settings[:consumer_key],
|
||||
|
@ -18,4 +15,4 @@ class CanvasTwitterConfig
|
|||
end
|
||||
|
||||
|
||||
Twitter::Connection.config = CanvasTwitterConfig.new
|
||||
Twitter::Connection.config = CanvasTwitterConfig
|
||||
|
|
|
@ -61,8 +61,8 @@ module LinkedIn
|
|||
end
|
||||
|
||||
def self.config=(config)
|
||||
if !config.is_a?(Proc)
|
||||
raise "Config must be a Proc"
|
||||
unless config.respond_to?(:call)
|
||||
raise "Config must respond to #call"
|
||||
end
|
||||
@config = config
|
||||
end
|
||||
|
|
|
@ -19,30 +19,56 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe LinkedIn::Connection do
|
||||
|
||||
let(:connection) { LinkedIn::Connection.new }
|
||||
|
||||
describe ".config" do
|
||||
it "accepts any object with a call interface" do
|
||||
conf_class= Class.new do
|
||||
def call
|
||||
{'some' => 'config'}
|
||||
end
|
||||
end
|
||||
|
||||
described_class.config = conf_class.new
|
||||
expect(described_class.config['some']).to eq('config')
|
||||
end
|
||||
|
||||
it "rejects uncallable configs" do
|
||||
expect { described_class.config = Object.new }.to(
|
||||
raise_error(RuntimeError) do |e|
|
||||
expect(e.message).to match(/must respond to/)
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "with valid configuration" do
|
||||
|
||||
before do
|
||||
config = {
|
||||
'api_key' => 'key',
|
||||
'secret_key' => 'secret'
|
||||
}
|
||||
LinkedIn::Connection.config = Proc.new do
|
||||
config
|
||||
LinkedIn::Connection.config = proc{ config }
|
||||
end
|
||||
end
|
||||
|
||||
let (:connection) {LinkedIn::Connection.new}
|
||||
|
||||
describe "#get_service_user_info" do
|
||||
it "returns service user info" do
|
||||
token_response_body = "<html><id>#1</id><first-name>john</first-name><last-name>doe</last-name><public-profile-url>http://example.com/linkedin</public-profile-url></html>"
|
||||
token_response_body = "<html><id>#1</id>"\
|
||||
"<first-name>john</first-name>"\
|
||||
"<last-name>doe</last-name>"\
|
||||
"<public-profile-url>http://example.com/linkedin</public-profile-url>"\
|
||||
"</html>"
|
||||
mock_access_token = stub()
|
||||
mock_access_token.expects(:get)
|
||||
.with('/v1/people/~:(id,first-name,last-name,public-profile-url,picture-url)')
|
||||
.returns(stub(body: token_response_body))
|
||||
|
||||
service_user_id, service_user_name, service_user_url = connection.get_service_user_info(mock_access_token)
|
||||
service_user_id.should == "#1"
|
||||
service_user_name.should == "john doe"
|
||||
service_user_url.should == "http://example.com/linkedin"
|
||||
expect(service_user_id).to eq("#1")
|
||||
expect(service_user_name).to eq("john doe")
|
||||
expect(service_user_url).to eq("http://example.com/linkedin")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,4 +124,5 @@ describe LinkedIn::Connection do
|
|||
LinkedIn::Connection.consumer('my_key', 'my_secret')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
require_relative '../spec_helper'
|
||||
require_relative '../../config/initializers/linked_in'
|
||||
|
||||
describe CanvasLinkedInConfig do
|
||||
|
||||
describe ".call" do
|
||||
it "returns a config with indifferent access" do
|
||||
plugin = stub(settings: {client_id: "abcdefg", client_secret_dec: "12345"})
|
||||
Canvas::Plugin.stubs(:find).with(:linked_in).returns(plugin)
|
||||
output = described_class.call
|
||||
expect(output['api_key']).to eq("abcdefg")
|
||||
expect(output[:api_key]).to eq("abcdefg")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -6,8 +6,8 @@ describe CanvasTwitterConfig do
|
|||
describe "#call" do
|
||||
it "returns a config with indifference access" do
|
||||
plugin = stub(settings: {consumer_key: "abcdefg", consumer_secret_dec: "12345"})
|
||||
config = described_class.new(plugin)
|
||||
output = config.call
|
||||
Canvas::Plugin.stubs(:find).with(:twitter).returns(plugin)
|
||||
output = described_class.call
|
||||
expect(output['api_key']).to eq("abcdefg")
|
||||
expect(output[:api_key]).to eq("abcdefg")
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue