* VRFS-3912 - more jamblaster tweaking
This commit is contained in:
parent
7f6b41d8b1
commit
9cc2ee4f4f
|
|
@ -1,2 +1,3 @@
|
|||
ALTER TABLE jamblaster_pairing_requests ALTER COLUMN sibling_key DROP NOT NULL;
|
||||
ALTER TABLE jamblaster_pairing_requests ADD COLUMN vtoken VARCHAR(400) NOT NULL;
|
||||
ALTER TABLE jamblaster_pairing_requests ADD COLUMN vtoken VARCHAR(400) NOT NULL;
|
||||
ALTER TABLE jamblaster_pairing_requests DROP COLUMN sibling_client_id;
|
||||
|
|
@ -7,8 +7,10 @@ module JamRuby
|
|||
validates :user, presence: true
|
||||
validates :jamblaster, presence: true
|
||||
validates :jamblaster_client_id, presence: true
|
||||
validates :sibling_client_id, presence: true
|
||||
validates :vtoken, presence: true
|
||||
|
||||
def key
|
||||
sibling_key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,61 +5,48 @@ class ApiJamblastersController < ApiController
|
|||
|
||||
# called from jamblaster
|
||||
def can_pair
|
||||
cid_a = params[:cid_a]
|
||||
cid_b = params[:cid_b]
|
||||
jbid = params[:jbid]
|
||||
user_id = params[:user_id]
|
||||
|
||||
connection_a = nil
|
||||
connection_b = nil
|
||||
|
||||
connection_a = Connection.find_by_client_id(cid_a) if cid_a
|
||||
connection_b = Connection.find_by_client_id(cid_b) if cid_b
|
||||
connection_a = Connection.find_by_client_id(jbid) if jbid
|
||||
user = User.find_by_id(user_id) if user_id
|
||||
|
||||
if connection_a.nil?
|
||||
render :json => {:message => 'No connection found with client_id ' + cid_a, reason: "cid_a"}, :status => 404
|
||||
render :json => {:message => "No connection found with client_id #{jbid}" , reason: "jbid"}, :status => 404
|
||||
return
|
||||
end
|
||||
|
||||
if connection_b.nil?
|
||||
render :json => {:message => 'No connection found with client_id ' + cid_b, reason: "cid_b"}, :status => 404
|
||||
if user.nil?
|
||||
render :json => {:message => "No user found with user id #{user_id}", reason: "user_id"}, :status => 404
|
||||
return
|
||||
end
|
||||
|
||||
user_a = connection_a.user
|
||||
user_b = connection_b.user
|
||||
|
||||
if user_a.nil?
|
||||
render :json => {:message => 'No connection found with client_id ' + user_a, reason: "user_a"}, :status => 404
|
||||
render :json => {:message => "No user found for jbid #{jbid}", reason: "user_a"}, :status => 404
|
||||
return
|
||||
end
|
||||
|
||||
if user_b.nil?
|
||||
render :json => {:message => 'No connection found with client_id ' + user_b, reason: "user_b"}, :status => 404
|
||||
return
|
||||
end
|
||||
|
||||
if user_a.id == user_b.id
|
||||
if user_a.id == user.id
|
||||
render :json => {}, :status => 200
|
||||
else
|
||||
render :json => {:message => 'Users do not match for both client IDs', reason: "can_not_pair"}, :status => 403
|
||||
render :json => {:message => "Users do not match for both client IDs", reason: "can_not_pair"}, :status => 403
|
||||
end
|
||||
end
|
||||
|
||||
def is_allowed
|
||||
#Pass the jbid & cbid. Reply is no error on true, else error
|
||||
jbid = params[:jbid]
|
||||
cbid = params[:cbid]
|
||||
user_id = params[:user_id]
|
||||
|
||||
jamblaster = Jamblaster.find_by_client_id!(jbid)
|
||||
|
||||
connection = Connection.find_by_client_id(cbid)
|
||||
if connection.nil?
|
||||
render :json => {:message => 'No connection found with client_id ' + cbid, reason: "cbid"}, :status => 404
|
||||
return
|
||||
end
|
||||
|
||||
user = connection.user
|
||||
user = User.find_by_id(user_id)
|
||||
if user.nil?
|
||||
render :json => {:message => 'No user associated with the connection ' + cbid, reason: "cbid"}, :status => 404
|
||||
render :json => {:message => "No user associated with the user #{user_id}", reason: "user_id"}, :status => 404
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -80,7 +67,7 @@ class ApiJamblastersController < ApiController
|
|||
@jamblaster = Jamblaster.where(client_id: jbid, serial_no: serial_no).first
|
||||
|
||||
if @jamblaster.nil?
|
||||
render :json => {:message => 'No jamblaster found with serial_no ' + serial_no + ' and jbid' + jbid, reason: "serial_no"}, :status => 404
|
||||
render :json => {:message => "No jamblaster found with serial_no #{serial_no} and jbid #{jbid}", reason: "serial_no"}, :status => 404
|
||||
return
|
||||
end
|
||||
end
|
||||
|
|
@ -101,7 +88,6 @@ class ApiJamblastersController < ApiController
|
|||
@pairing.user = current_user
|
||||
@pairing.jamblaster_client_id = params[:jbid]
|
||||
@pairing.jamblaster = jamblaster
|
||||
@pairing.sibling_client_id = params[:scid]
|
||||
@pairing.vtoken = params[:vtoken]
|
||||
if !@pairing.save
|
||||
respond_with_model(@pairing)
|
||||
|
|
@ -111,20 +97,20 @@ class ApiJamblastersController < ApiController
|
|||
end
|
||||
|
||||
def login
|
||||
scid = params[:scid]
|
||||
user_id = params[:user_id]
|
||||
jbid = params[:jbid]
|
||||
vtoken = params[:vtoken]
|
||||
serial_no = params[:serial_no]
|
||||
pairing_request = JamblasterPairingRequest.where(jamblaster_client_id: jbid).where(sibling_client_id: scid).where(vtoken: vtoken).first
|
||||
pairing_request = JamblasterPairingRequest.where(jamblaster_client_id: jbid).where(user_id: user_id).where(vtoken: vtoken).first
|
||||
jamblaster = Jamblaster.find_by_serial_no(serial_no)
|
||||
|
||||
if jamblaster.nil?
|
||||
render :json => {:message => 'No jamblaster found with serial_no ' + serial_no, reason: "serial_no"}, :status => 404
|
||||
render :json => {:message => "No jamblaster found with serial_no #{serial_no}" , reason: "serial_no"}, :status => 404
|
||||
return
|
||||
end
|
||||
|
||||
if pairing_request.nil?
|
||||
render :json => {:message => "No pairing request found with jbid=#{jbid} && sibling_client_id=#{scid} && vtoken=#{vtokne}", reason: "no_pairing_request"}, :status => 404
|
||||
render :json => {:message => "No pairing request found with jbid=#{jbid} && user_id=#{user_id} && vtoken=#{vtoken}", reason: "no_pairing_request"}, :status => 404
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -161,7 +147,7 @@ class ApiJamblastersController < ApiController
|
|||
def pair
|
||||
key = params[:key]
|
||||
vtoken = params[:vtoken]
|
||||
scid = params[:scid]
|
||||
user_id = params[:user_id]
|
||||
jbid = params[:jbid]
|
||||
|
||||
jamblaster = Jamblaster.find_by_client_id!(jbid)
|
||||
|
|
@ -188,7 +174,7 @@ class ApiJamblastersController < ApiController
|
|||
if !pairing_request.save
|
||||
respond_with_model(pairing_request)
|
||||
else
|
||||
Jamblaster.send_pair_attempt(jbid, scid, key)
|
||||
Jamblaster.send_pair_attempt(jbid, user_id, key)
|
||||
@jamblaster = jamblaster
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@ object @jamblaster
|
|||
attributes :id, :serial_no, :client_id
|
||||
|
||||
child(:jamblaster_pairing_requests => :pairings) {
|
||||
attributes :sibling_client_id, :jamblaster_client_id, :vtoken, :key
|
||||
attributes :id, :user_id, :sibling_client_id, :vtoken, :key
|
||||
}
|
||||
|
|
@ -3,5 +3,5 @@ object @jamblasters
|
|||
attributes :id, :serial_no, :client_id
|
||||
|
||||
child(:jamblaster_pairing_requests => :pairings) {
|
||||
attributes :sibling_client_id, :jamblaster_client_id, :vtoken, :key
|
||||
attributes :id, :user_id, :sibling_client_id, :jamblaster_client_id, :vtoken, :key
|
||||
}
|
||||
|
|
@ -14,9 +14,8 @@ describe ApiJamblastersController do
|
|||
describe "can_pair" do
|
||||
it "works" do
|
||||
connection1 = FactoryGirl.create(:connection, :user => user, client_id: 'abc1')
|
||||
connection2 = FactoryGirl.create(:connection, :user => user, client_id: 'abc2')
|
||||
|
||||
get :can_pair, {:format => 'json', cid_a: connection1.client_id, cid_b: connection2.client_id}
|
||||
get :can_pair, {:format => 'json', jbid: connection1.client_id, user_id: user.id}
|
||||
response.status.should == 200
|
||||
end
|
||||
end
|
||||
|
|
@ -28,9 +27,7 @@ describe ApiJamblastersController do
|
|||
end
|
||||
|
||||
it "works" do
|
||||
connection1 = FactoryGirl.create(:connection, :user => user, client_id: 'client_id3')
|
||||
|
||||
get :is_allowed, {:format => 'json', jbid: jamblaster.client_id, cbid: connection1.client_id}
|
||||
get :is_allowed, {:format => 'json', jbid: jamblaster.client_id, user_id: user.id}
|
||||
response.status.should == 200
|
||||
end
|
||||
end
|
||||
|
|
@ -82,19 +79,19 @@ describe ApiJamblastersController do
|
|||
end
|
||||
|
||||
it "works" do
|
||||
post :start_pairing, {:format => 'json', jbid: jamblaster.client_id, scid: 'sibling_id', vtoken: 'vtoken'}
|
||||
json = JSON.parse(response.body)
|
||||
post :start_pairing, {:format => 'json', jbid: jamblaster.client_id, vtoken: 'vtoken'}
|
||||
response.status.should == 200
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
request = JamblasterPairingRequest.where(jamblaster_id: jamblaster.id).first
|
||||
request.should_not be_nil
|
||||
request.user.should eql(user)
|
||||
request.vtoken.should eq 'vtoken'
|
||||
request.sibling_client_id.should eq 'sibling_id'
|
||||
|
||||
end
|
||||
|
||||
it "returns 422 if bogus jamblaster" do
|
||||
post :start_pairing, {:format => 'json', jbid: 'nada', scid: 'sibling_id', vtoken: 'vtoken'}
|
||||
post :start_pairing, {:format => 'json', jbid: 'nada', vtoken: 'vtoken'}
|
||||
json = JSON.parse(response.body)
|
||||
response.status.should == 422
|
||||
json = JSON.parse(response.body)
|
||||
|
|
@ -114,17 +111,16 @@ describe ApiJamblastersController do
|
|||
end
|
||||
|
||||
it "works" do
|
||||
post :start_pairing, {:format => 'json', jbid: jamblaster.client_id, scid: 'sibling_id2', vtoken: 'vtoken2'}
|
||||
post :start_pairing, {:format => 'json', jbid: jamblaster.client_id, vtoken: 'vtoken2'}
|
||||
response.status.should == 200
|
||||
|
||||
request = JamblasterPairingRequest.where(jamblaster_client_id: jamblaster.client_id, vtoken: 'vtoken2', sibling_client_id: 'sibling_id2').first
|
||||
request = JamblasterPairingRequest.where(jamblaster_client_id: jamblaster.client_id, vtoken: 'vtoken2', user_id: user.id).first
|
||||
request.should_not be_nil
|
||||
request.user.should eql(user)
|
||||
request.vtoken.should eq 'vtoken2'
|
||||
request.sibling_client_id.should eq 'sibling_id2'
|
||||
request.jamblaster_client_id.should eq jamblaster.client_id
|
||||
|
||||
post :login, {:format => 'json', jbid: jamblaster.client_id, serial_no: jamblaster.serial_no, scid: 'sibling_id2', vtoken: 'vtoken2'}
|
||||
post :login, {:format => 'json', jbid: jamblaster.client_id, serial_no: jamblaster.serial_no, user_id: user.id, vtoken: 'vtoken2'}
|
||||
json = JSON.parse(response.body)
|
||||
response.status.should == 200
|
||||
end
|
||||
|
|
@ -139,21 +135,20 @@ describe ApiJamblastersController do
|
|||
|
||||
it "works" do
|
||||
|
||||
post :start_pairing, {:format => 'json', jbid: jamblaster.client_id, scid: 'sibling_id4', vtoken: 'vtoken4'}
|
||||
post :start_pairing, {:format => 'json', jbid: jamblaster.client_id, vtoken: 'vtoken4'}
|
||||
response.status.should == 200
|
||||
|
||||
request = JamblasterPairingRequest.where(jamblaster_client_id: jamblaster.client_id, vtoken: 'vtoken4', sibling_client_id: 'sibling_id4').first
|
||||
request = JamblasterPairingRequest.where(jamblaster_client_id: jamblaster.client_id, vtoken: 'vtoken4', user_id: user.id).first
|
||||
request.should_not be_nil
|
||||
request.user.should eql(user)
|
||||
request.vtoken.should eq 'vtoken4'
|
||||
request.sibling_client_id.should eq 'sibling_id4'
|
||||
request.jamblaster_client_id.should eq jamblaster.client_id
|
||||
|
||||
post :login, {:format => 'json', jbid: jamblaster.client_id, serial_no: jamblaster.serial_no, scid: 'sibling_id4', vtoken: 'vtoken4'}
|
||||
post :login, {:format => 'json', jbid: jamblaster.client_id, serial_no: jamblaster.serial_no, user_id: user.id, vtoken: 'vtoken4'}
|
||||
json = JSON.parse(response.body)
|
||||
response.status.should == 200
|
||||
|
||||
post :pair, {:format => 'json', vtoken: 'vtoken4', scid: 'sibling_id4', jbid: jamblaster.client_id, key: 'abc'}
|
||||
post :pair, {:format => 'json', vtoken: 'vtoken4', user_id: user.id, jbid: jamblaster.client_id, key: 'abc'}
|
||||
response.status.should == 200
|
||||
json = JSON.parse(response.body)
|
||||
json["id"].should eq jamblaster.id
|
||||
|
|
|
|||
Loading…
Reference in New Issue