From fdbdf53ec6c0548304cb51bc4fb036c7931811b0 Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Sat, 1 Mar 2014 16:54:23 -0600 Subject: [PATCH 01/15] fix the variable names for record to be more natural --- web/app/controllers/api_scoring_controller.rb | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/web/app/controllers/api_scoring_controller.rb b/web/app/controllers/api_scoring_controller.rb index 19ae307b5..eff9dd485 100644 --- a/web/app/controllers/api_scoring_controller.rb +++ b/web/app/controllers/api_scoring_controller.rb @@ -36,49 +36,53 @@ class ApiScoringController < ApiController def record # aclientid, aAddr, bclientid, bAddr, score returns nothing - aclient_id = params[:aclientid] + #puts "================= record #{params.inspect}" + aclientid = params[:aclientid] aip_address = params[:aAddr] - bclient_id = params[:bclientid] + bclientid = params[:bclientid] bip_address = params[:bAddr] score = params[:score] - if aclient_id.nil? then render :json => {message: 'aclient_id not specified'}, :status => 400; return end + if aclientid.nil? then render :json => {message: 'aclientid not specified'}, :status => 400; return end if aip_address.nil? then render :json => {message: 'aAddr not specified'}, :status => 400; return end - if bclient_id.nil? then render :json => {message: 'bclient_id not specified'}, :status => 400; return end + if bclientid.nil? then render :json => {message: 'bclientid not specified'}, :status => 400; return end if bip_address.nil? then render :json => {message: 'bAddr not specified'}, :status => 400; return end - if score.nil? then render :json => {message: 'score not specified'}, :status => 400; return end - aaddr = JamRuby::JamIsp.ip_to_num(aip_address) - if aaddr.nil? then render :json => {message: 'aAddr not valid ip_address'}, :status => 400; return end + # no score means the test was run but failed, details should still be recorded for later consideration + if score.nil? then render :json => {message: 'score not specified'}, :status => 200; return end - baddr = JamRuby::JamIsp.ip_to_num(bip_address) - if baddr.nil? then render :json => {message: 'bAddr not valid ip_address'}, :status => 400; return end + aAddr = JamRuby::JamIsp.ip_to_num(aip_address) + if aAddr.nil? then render :json => {message: 'aAddr not valid ip_address'}, :status => 400; return end - if aaddr == baddr then render :json => {message: 'aAddr and bAddr are the same'}, :status => 403; return end + bAddr = JamRuby::JamIsp.ip_to_num(bip_address) + if bAddr.nil? then render :json => {message: 'bAddr not valid ip_address'}, :status => 400; return end + + if aAddr == bAddr then render :json => {message: 'aAddr and bAddr are the same'}, :status => 403; return end if !score.is_a? Numeric then render :json => {message: 'score not valid numeric'}, :status => 400; return end - aconn = Connection.where(client_id: aclient_id).first + aconn = Connection.where(client_id: aclientid).first if aconn.nil? then render :json => {message: 'a\'s session not found'}, :status => 404; return end - if aaddr != aconn.addr then render :json => {message: 'a\'s session addr does not match aAddr'}, :status => 403; return end + if aAddr != aconn.addr then render :json => {message: 'a\'s session addr does not match aAddr'}, :status => 403; return end if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\' session not owned by user'}, :status => 403; return end - bconn = Connection.where(client_id: bclient_id).first + bconn = Connection.where(client_id: bclientid).first if bconn.nil? then render :json => {message: 'b\'s session not found'}, :status => 404; return end - if baddr != bconn.addr then render :json => {message: 'b\'s session addr does not match bAddr'}, :status => 403; return end + if bAddr != bconn.addr then render :json => {message: 'b\'s session addr does not match bAddr'}, :status => 403; return end if score < 0 or score > 999 then render :json => {message: 'score < 0 or score > 999'}, :status => 403; return end - aloc = JamRuby::GeoIpBlocks.lookup(aaddr) - aisp = JamRuby::JamIsp.lookup(aaddr) + aloc = JamRuby::GeoIpBlocks.lookup(aAddr) + aisp = JamRuby::JamIsp.lookup(aAddr) if aisp.nil? or aloc.nil? then render :json => {message: 'a\'s location or isp not found'}, :status => 404; return end alocidispid = aloc.locid*1000000+aisp.coid; - bloc = JamRuby::GeoIpBlocks.lookup(baddr) - bisp = JamRuby::JamIsp.lookup(baddr) + bloc = JamRuby::GeoIpBlocks.lookup(bAddr) + bisp = JamRuby::JamIsp.lookup(bAddr) + if bisp.nil? or bloc.nil? then render :json => {message: 'b\'s location or isp not found'}, :status => 404; return end blocidispid = bloc.locid*1000000+bisp.coid - JamRuby::Score.createx(alocidispid, aclient_id, aaddr, blocidispid, bclient_id, baddr, score.ceil, nil) + JamRuby::Score.createx(alocidispid, aclientid, aAddr, blocidispid, bclientid, bAddr, score.ceil, nil) render :json => {}, :status => 200 end From 5d899f57dd238f180aa6974807486783ffabbb26 Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Sat, 1 Mar 2014 20:36:51 -0600 Subject: [PATCH 02/15] complete unit tests for api_scoring_controller and add some better test data --- db/manifest | 1 + db/up/scores_better_test_data.sql | 71 +++++++ ruby/lib/jam_ruby/models/jam_isp.rb | 10 +- web/app/controllers/api_scoring_controller.rb | 34 +-- .../api_scoring_controller_spec.rb | 200 ++++++++++++------ 5 files changed, 228 insertions(+), 88 deletions(-) create mode 100644 db/up/scores_better_test_data.sql diff --git a/db/manifest b/db/manifest index f82a62034..175b7a29b 100755 --- a/db/manifest +++ b/db/manifest @@ -125,3 +125,4 @@ scores_mod_connections2.sql track_download_counts.sql scores_mod_users2.sql user_bio.sql +scores_better_test_data.sql diff --git a/db/up/scores_better_test_data.sql b/db/up/scores_better_test_data.sql new file mode 100644 index 000000000..89ad5f388 --- /dev/null +++ b/db/up/scores_better_test_data.sql @@ -0,0 +1,71 @@ +-- cooking up some better test data for use with findblah + +delete from GeoIPLocations; +insert into GeoIPLocations (locId, countryCode, region, city, postalCode, latitude, longitude, metroCode, areaCode) values + (17192,'US','TX','Austin','78749',30.2076,-97.8587,635,'512'), + (667,'US','TX','Dallas','75207',32.7825,-96.8207,623,'214'), + (30350,'US','TX','Houston','77001',29.7633,-95.3633,618,'713'), + (31423,'US','CO','Denver','80201',39.7392,-104.9847,751,'303'), + (1807,'US','TX','San Antonio','78201',29.4713,-98.5353,641,'210'), + (23565,'US','FL','Miami','33101',25.7743,-80.1937,528,'305'), + (11704,'US','FL','Tampa','33601',27.9475,-82.4584,539,'813'), + (26424,'US','MA','Boston','02101',42.3584,-71.0598,506,'617'), + (5059,'US','ME','Portland','04101',43.6589,-70.2615,500,'207'), + (2739,'US','OR','Portland','97201',45.5073,-122.6932,820,'503'), + (1539,'US','WA','Seattle','98101',47.6103,-122.3341,819,'206'), + (2720,'US','CA','Mountain View','94040',37.3845,-122.0881,807,'650'), + (154078,'US','AR','Mountain View','72560',35.8732,-92.0717,693,'870'), + (3964,'US','CA','Barstow','92311',34.9701,-116.9929,803,'760'), + (14447,'US','OK','Tulsa','74101',36.154,-95.9928,671,'918'), + (162129,'US','TN','Memphis','37501',35.1693,-89.9904,640,'713'); + +delete from GeoIPBlocks; +insert into GeoIPBlocks (beginIp, endIp, locId) values + (x'00000000'::bigint,x'0FFFFFFF'::bigint,17192), + (x'10000000'::bigint,x'1FFFFFFF'::bigint,667), + (x'20000000'::bigint,x'2FFFFFFF'::bigint,30350), + (x'30000000'::bigint,x'3FFFFFFF'::bigint,31423), + (x'40000000'::bigint,x'4FFFFFFF'::bigint,1807), + (x'50000000'::bigint,x'5FFFFFFF'::bigint,23565), + (x'60000000'::bigint,x'6FFFFFFF'::bigint,11704), + (x'70000000'::bigint,x'7FFFFFFF'::bigint,26424), + (x'80000000'::bigint,x'8FFFFFFF'::bigint,5059), + (x'90000000'::bigint,x'9FFFFFFF'::bigint,2739), + (x'A0000000'::bigint,x'AFFFFFFF'::bigint,1539), + (x'B0000000'::bigint,x'BFFFFFFF'::bigint,2720), + (x'C0000000'::bigint,x'CFFFFFFF'::bigint,154078), + (x'D0000000'::bigint,x'DFFFFFFF'::bigint,3964), + (x'E0000000'::bigint,x'EFFFFFFF'::bigint,14447), + (x'F0000000'::bigint,x'FFFEFFFF'::bigint,162129); +-- (x'FFFF0000'::bigint,x'FFFFFFFF'::bigint,bogus) + +delete from GeoIPISP; +insert into GeoIPISP values + (x'00000000'::bigint,x'0FFFFFFF'::bigint,'Intergalactic Boogie'), + (x'10000000'::bigint,x'1FFFFFFF'::bigint,'Powerful Pipes'), + (x'20000000'::bigint,x'2FFFFFFF'::bigint,'Powerful Pipes'), + (x'30000000'::bigint,x'3FFFFFFF'::bigint,'Intergalactic Boogie'), + (x'40000000'::bigint,x'4FFFFFFF'::bigint,'Tangled Webs'), + (x'50000000'::bigint,x'5FFFFFFF'::bigint,'Tangled Webs'), + (x'60000000'::bigint,x'6FFFFFFF'::bigint,'Powerful Pipes'), + (x'70000000'::bigint,x'7FFFFFFF'::bigint,'Intergalactic Boogie'), + (x'80000000'::bigint,x'8FFFFFFF'::bigint,'Greasy Lightning'), + (x'90000000'::bigint,x'9FFFFFFF'::bigint,'Powerful Pipes'), + (x'A0000000'::bigint,x'AFFFFFFF'::bigint,'Intergalactic Boogie'), + (x'B0000000'::bigint,x'BFFFFFFF'::bigint,'Tangled Webs'), + (x'C0000000'::bigint,x'CFFFFFFF'::bigint,'Greasy Lightning'), + (x'D0000000'::bigint,x'DFFFFFFF'::bigint,'Tangled Webs'), + (x'E0000000'::bigint,x'EFFFFFFF'::bigint,'Intergalactic Boogie'), + (x'F0000000'::bigint,x'FFFEFFFF'::bigint,'Powerful Pipes'); +-- (x'FFFF0000'::bigint,x'FFFFFFFF'::bigint,'bogus') + +DELETE FROM jamcompany; +ALTER SEQUENCE jamcompany_coid_seq RESTART WITH 1; +INSERT INTO jamcompany (company) SELECT DISTINCT company FROM geoipisp ORDER BY company; + +DELETE FROM jamisp; +INSERT INTO jamisp (beginip, endip, coid) SELECT x.beginip, x.endip, y.coid FROM geoipisp x, jamcompany y WHERE x.company = y.company; + +UPDATE geoiplocations SET geog = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography; +UPDATE geoipblocks SET geom = ST_MakeEnvelope(beginip, -1, endip, 1); +UPDATE jamisp SET geom = ST_MakeEnvelope(beginip, -1, endip, 1); diff --git a/ruby/lib/jam_ruby/models/jam_isp.rb b/ruby/lib/jam_ruby/models/jam_isp.rb index 680cd302a..3c2c7bb81 100644 --- a/ruby/lib/jam_ruby/models/jam_isp.rb +++ b/ruby/lib/jam_ruby/models/jam_isp.rb @@ -6,9 +6,13 @@ module JamRuby self.table_name = 'jamisp' def self.ip_to_num(ip_addr) - i = IPAddr.new(ip_addr) - return i.to_i if i.ipv4? - nil + begin + i = IPAddr.new(ip_addr) + return i.to_i if i.ipv4? + nil + rescue IPAddr::InvalidAddressError + nil + end end def self.lookup(ipnum) diff --git a/web/app/controllers/api_scoring_controller.rb b/web/app/controllers/api_scoring_controller.rb index eff9dd485..5ba61122d 100644 --- a/web/app/controllers/api_scoring_controller.rb +++ b/web/app/controllers/api_scoring_controller.rb @@ -4,32 +4,32 @@ class ApiScoringController < ApiController before_filter :api_signed_in_user def work # clientid; returns another clientid - client_id = params[:clientid] - if client_id.nil? then render :json => {message: 'client_id not specified'}, :status => 400; return end + clientid = params[:clientid] + if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end - c = Connection.where(client_id: client_id).first - if c.nil? then render :json => {message: 'connection not found'}, :status => 404; return end - if !c.user.id.eql?(current_user.id) then render :json => {message: 'user does not own client_id'}, :status => 403; return end + conn = Connection.where(client_id: clientid).first + if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end + if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end # todo this method is a stub - #puts "ApiScoringController#work(#{client_id}) => locidispid #{c.locidispid}" - result_client_id = JamRuby::GetWork.get_work(c.locidispid) - #result_client_id = client_id+'peer' + #puts "ApiScoringController#work(#{clientid}) => locidispid #{c.locidispid}" + result_client_id = JamRuby::GetWork.get_work(conn.locidispid) + #result_client_id = clientid+'peer' render :json => {:clientid => result_client_id}, :status => 200 end def worklist # clientid; returns a list of clientid - client_id = params[:clientid] - if client_id.nil? then render :json => {message: 'client_id not specified'}, :status => 400; return end + clientid = params[:clientid] + if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end - c = Connection.where(client_id: client_id).first - if c.nil? then render :json => {message: 'connection not found'}, :status => 404; return end - if !c.user.id.eql?(current_user.id) then render :json => {message: 'user does not own client_id'}, :status => 403; return end + conn = Connection.where(client_id: clientid).first + if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end + if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end # todo this method is a stub - result_client_ids = JamRuby::GetWork.get_work_list(c.locidispid) - #result_client_ids = [client_id+'peer1', client_id+'peer2'] + result_client_ids = JamRuby::GetWork.get_work_list(conn.locidispid) + #result_client_ids = [clientid+'peer1', clientid+'peer2'] render :json => {:clientids => result_client_ids}, :status => 200 end @@ -49,7 +49,7 @@ class ApiScoringController < ApiController if bip_address.nil? then render :json => {message: 'bAddr not specified'}, :status => 400; return end # no score means the test was run but failed, details should still be recorded for later consideration - if score.nil? then render :json => {message: 'score not specified'}, :status => 200; return end + if score.nil? then render :json => {message: 'score not specified'}, :status => 400; return end aAddr = JamRuby::JamIsp.ip_to_num(aip_address) if aAddr.nil? then render :json => {message: 'aAddr not valid ip_address'}, :status => 400; return end @@ -64,7 +64,7 @@ class ApiScoringController < ApiController aconn = Connection.where(client_id: aclientid).first if aconn.nil? then render :json => {message: 'a\'s session not found'}, :status => 404; return end if aAddr != aconn.addr then render :json => {message: 'a\'s session addr does not match aAddr'}, :status => 403; return end - if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\' session not owned by user'}, :status => 403; return end + if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\'s session not owned by user'}, :status => 403; return end bconn = Connection.where(client_id: bclientid).first if bconn.nil? then render :json => {message: 'b\'s session not found'}, :status => 404; return end diff --git a/web/spec/controllers/api_scoring_controller_spec.rb b/web/spec/controllers/api_scoring_controller_spec.rb index 0cc5399dc..7a3b71911 100644 --- a/web/spec/controllers/api_scoring_controller_spec.rb +++ b/web/spec/controllers/api_scoring_controller_spec.rb @@ -4,17 +4,21 @@ describe ApiScoringController do render_views BOGUS_CLIENT_ID = 'nobodyclientid' - BOGUS_IP_ADDRESS = '0.0.0.0' + BOGUS_IP_ADDRESS = '1.2.3.4' + BAD_IP_ADDRESS = 'a.b.c.d' MARY_IP_ADDRESS = '75.92.54.210' # 1264334546, 4B.5C.36.D2 MARY_ADDR = 1264334546 + MARY_LOCIDISPID = 17192008423 MIKE_IP_ADDRESS = '173.172.108.1' # 2913758209, AD.AC.6C.01 MIKE_ADDR = 2913758209 - - MARY_LOCIDISPID = 17192008423 MIKE_LOCIDISPID = 17192043640 + JOHN_IP_ADDRESS = '255.255.1.2' # 4294902018, FF.FF.01.02 + JOHN_ADDR = 4294902018 + JOHN_LOCIDISPID = 0 + before do @mary = FactoryGirl.create(:user, first_name: 'mary') @mary_connection = FactoryGirl.create(:connection, user: @mary, ip_address: MARY_IP_ADDRESS, addr: MARY_ADDR, locidispid: MARY_LOCIDISPID) @@ -23,6 +27,10 @@ describe ApiScoringController do @mike = FactoryGirl.create(:user, first_name: 'mike') @mike_connection = FactoryGirl.create(:connection, user: @mike, ip_address: MIKE_IP_ADDRESS, addr: MIKE_ADDR, locidispid: MIKE_LOCIDISPID) @mike_client_id = @mike_connection.client_id + + @john = FactoryGirl.create(:user, first_name: 'john') + @john_connection = FactoryGirl.create(:connection, user: @john, ip_address: JOHN_IP_ADDRESS, addr: JOHN_ADDR, locidispid: JOHN_LOCIDISPID) + @john_client_id = @john_connection.client_id end after do @@ -30,6 +38,8 @@ describe ApiScoringController do @mary.delete @mike_connection.delete @mike.delete + @john_connection.delete + @john.delete end before(:each) do @@ -40,34 +50,34 @@ describe ApiScoringController do describe 'work' do - it 'try work with nobody and nobody' do - controller.current_user = nil - get :work, {} - response.should_not be_success - json = JSON.parse(response.body, :symbolize_names => true) - json.length.should == 1 - json[:message].should_not be_nil - end - - it 'try work with mary and nobody' do - controller.current_user = @mary - get :work, {} - response.should_not be_success - json = JSON.parse(response.body, :symbolize_names => true) - json.length.should == 1 - json[:message].should_not be_nil - end - - it 'try work with nobody and mary' do + it 'try work with nobody login and mary' do controller.current_user = nil get :work, {clientid: @mary_client_id} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('not logged in') end - it 'try work with mary and mary' do + it 'try work with mary login and nothing' do + controller.current_user = @mary + get :work, {} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('clientid not specified') + end + + it 'try work with mary login and bogus' do + controller.current_user = @mary + get :work, {clientid: BOGUS_CLIENT_ID} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('session not found') + end + + it 'try work with mary login and mary' do controller.current_user = @mary get :work, {clientid: @mary_client_id} response.should be_success @@ -77,7 +87,7 @@ describe ApiScoringController do [@mary_client_id, @mike_client_id].should include(json[:clientid]) end - it 'try work with mike and mike' do + it 'try work with mike login and mike' do controller.current_user = @mike get :work, {clientid: @mike_client_id} response.should be_success @@ -87,47 +97,56 @@ describe ApiScoringController do [@mary_client_id, @mike_client_id].should include(json[:clientid]) end - it 'try work with mike and mary' do + it 'try work with mary login and mike' do + controller.current_user = @mary + get :work, {clientid: @mike_client_id} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('session not owned by user') + end + + it 'try work with mike login and mary' do controller.current_user = @mike get :work, {clientid: @mary_client_id} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('session not owned by user') end end describe 'worklist' do - it 'try worklist with nobody and nobody' do + it 'try worklist with nobody login and nobody' do controller.current_user = nil get :worklist, {} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('not logged in') end - it 'try worklist with mary and nobody' do + it 'try worklist with mary login and nobody' do controller.current_user = @mary get :worklist, {} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('clientid not specified') end - it 'try worklist with nobody and mary' do + it 'try worklist with nobody login and mary' do controller.current_user = nil get :worklist, {clientid: @mary_client_id} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('not logged in') end - it 'try worklist with mary and mary' do + it 'try worklist with mary login and mary' do controller.current_user = @mary get :worklist, {clientid: @mary_client_id} response.should be_success @@ -142,7 +161,7 @@ describe ApiScoringController do end - it 'try worklist with mike and mike' do + it 'try worklist with mike login and mike' do controller.current_user = @mike get :worklist, {clientid: @mike_client_id} response.should be_success @@ -156,26 +175,26 @@ describe ApiScoringController do json[:clientids][0].should_not eql(json[:clientids][1]) end - it 'try worklist with mary and mike' do + it 'try worklist with mary login and mike' do controller.current_user = @mary get :worklist, {clientid: @mike_client_id} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('session not owned by user') end end describe 'record' do - it 'record with no login, mary, mary_ip_address, mike, mike_addr, score' do + it 'record with nobody login, mary, mary_ip_address, mike, mike_addr, score' do controller.current_user = nil post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 20} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('not logged in') end it 'record with mary login, nil, mary_addr, mike, mike_addr, score' do @@ -184,7 +203,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('aclientid not specified') end it 'record with mary login, mary, nil, mike, mike_addr, score' do @@ -193,7 +212,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('aAddr not specified') end it 'record with mary login, mary, mary_addr, nil, mike_addr, score' do @@ -202,7 +221,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('bclientid not specified') end it 'record with mary login, mary, mary_addr, mike, nil, score' do @@ -211,7 +230,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('bAddr not specified') end it 'record with mary login, mary, mary_addr, mike, mike_addr, nil' do @@ -220,7 +239,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('score not specified') end it 'record with mary login, bogus, mary_addr, mike, mike_addr, score' do @@ -229,7 +248,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('a\'s session not found') end it 'record with mary login, mary, mary_addr, bogus, mike_addr, score' do @@ -238,7 +257,16 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('b\'s session not found') + end + + it 'record with mary login, mary, bogus, mike, mike_addr, score' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => BAD_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 20} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('aAddr not valid ip_address') end it 'record with mary login, mary, bogus, mike, mike_addr, score' do @@ -247,7 +275,16 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('a\'s session addr does not match aAddr') + end + + it 'record with mary login, mary, mary_addr, mike, bogus, score' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => BAD_IP_ADDRESS, :score => 20} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('bAddr not valid ip_address') end it 'record with mary login, mary, mary_addr, mike, bogus, score' do @@ -256,7 +293,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('b\'s session addr does not match bAddr') end it 'record with mary login, mike, mike_addr, mary, mary_addr, score' do @@ -265,25 +302,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil - end - - it 'record with mary login, mary, mary_addr, mike, mike_addr, -1' do - controller.current_user = @mary - post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => -1} - response.should_not be_success - json = JSON.parse(response.body, :symbolize_names => true) - json.length.should == 1 - json[:message].should_not be_nil - end - - it 'record with mary login, mary, mary_addr, mike, mike_addr, 1000' do - controller.current_user = @mary - post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 1000} - response.should_not be_success - json = JSON.parse(response.body, :symbolize_names => true) - json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('a\'s session not owned by user') end it 'record with mary login, mary, mary_addr, mary, mary_addr, score' do @@ -292,7 +311,52 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('aAddr and bAddr are the same') + end + + it 'record with mary login, mary, mary_addr, mike, mike_addr, -1' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => -1} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('score < 0 or score > 999') + end + + it 'record with mary login, mary, mary_addr, mike, mike_addr, 1000' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 1000} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('score < 0 or score > 999') + end + + it 'record with mary login, mary, mary_addr, mike, mike_addr, bogus' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 'abc'} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('score not valid numeric') + end + + it 'record with john login, john, john_addr, mike, mike_addr, bogus' do + controller.current_user = @john + post :record, {:format => 'json', :aclientid => @john_client_id, :aAddr => JOHN_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 20} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('a\'s location or isp not found') + end + + it 'record with mary login, mary, mary_addr, john, john_addr, bogus' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @john_client_id, :bAddr => JOHN_IP_ADDRESS, :score => 20} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('b\'s location or isp not found') end it 'record with mary login, mary, mary_addr, mike, mike_addr, score' do From 55de15338feec6afb1b7dd634a9de6283cd96a75 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 2 Mar 2014 15:05:27 -0500 Subject: [PATCH 03/15] fix dead link --- web/app/views/clients/_ftue.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/app/views/clients/_ftue.html.erb b/web/app/views/clients/_ftue.html.erb index aa71a3397..d7151d411 100644 --- a/web/app/views/clients/_ftue.html.erb +++ b/web/app/views/clients/_ftue.html.erb @@ -112,7 +112,7 @@ - + From 11a9d8b77bd2c98f6eb13532511776e95a35c8ea Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 2 Mar 2014 15:06:23 -0500 Subject: [PATCH 04/15] VRFS-604 show disconnected devices on audio profile screen --- .../javascripts/accounts_audio_profile.js | 27 +++++++++++++++---- .../stylesheets/client/account.css.scss | 6 +++++ .../clients/_account_audio_profile.html.erb | 25 +++++++++-------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/web/app/assets/javascripts/accounts_audio_profile.js b/web/app/assets/javascripts/accounts_audio_profile.js index b174689bc..a588452e5 100644 --- a/web/app/assets/javascripts/accounts_audio_profile.js +++ b/web/app/assets/javascripts/accounts_audio_profile.js @@ -30,21 +30,38 @@ function populateAccountAudio() { - // load Audio Driver dropdown - var devices = context.jamClient.TrackGetDevices(); + var badAudioConfigs = []; + var allAudioConfigs = context.jamClient.FTUEGetAllAudioConfigurations(); + var goodAudioConfigs = context.jamClient.FTUEGetGoodAudioConfigurations(); + for (var i=0; i < allAudioConfigs.length; i++) { + console.log("allAudioConfigs[i]=%o", allAudioConfigs[i]); + if ($.inArray(allAudioConfigs[i], goodAudioConfigs) === -1) { + console.log("pushing %o onto badAudioConfigs", allAudioConfigs[i]); + badAudioConfigs.push(allAudioConfigs[i]); + } + } + + // render CONNECTED device profiles var options = { - devices: devices + configurations: goodAudioConfigs, + valid: 1 } var template = context._.template($('#template-account-audio').html(), options, {variable: 'data'}); - appendAudio(template); + // render DISCONNECTED device profiles + options = { + configurations: badAudioConfigs, + valid: 0 + } + template = context._.template($('#template-account-audio').html(), options, {variable: 'data'}); + appendAudio(template); } function appendAudio(template) { - $('#account-audio-content-scroller table tbody').replaceWith(template); + $('#account-audio-content-scroller table tbody').append(template); } function resetForm() { diff --git a/web/app/assets/stylesheets/client/account.css.scss b/web/app/assets/stylesheets/client/account.css.scss index 341969dac..35beafe14 100644 --- a/web/app/assets/stylesheets/client/account.css.scss +++ b/web/app/assets/stylesheets/client/account.css.scss @@ -162,7 +162,13 @@ } } + tr.invalid-profile { + background-color:red; + } + img.invalid-profile { + vertical-align:middle; + } .button-grey { margin-right:6px; diff --git a/web/app/views/clients/_account_audio_profile.html.erb b/web/app/views/clients/_account_audio_profile.html.erb index c16a0394b..9470b27a2 100644 --- a/web/app/views/clients/_account_audio_profile.html.erb +++ b/web/app/views/clients/_account_audio_profile.html.erb @@ -34,25 +34,28 @@ -
+
+
+
+
+
+ — INVALID CONFIGURATION OR DEVICE NOT CONNECTED +
From 25a4e14e3a12951a283e77225f5a677202f73fc7 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 2 Mar 2014 15:14:54 -0500 Subject: [PATCH 05/15] VRFS-604 clear html before appending --- web/app/assets/javascripts/accounts_audio_profile.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/app/assets/javascripts/accounts_audio_profile.js b/web/app/assets/javascripts/accounts_audio_profile.js index a588452e5..868452660 100644 --- a/web/app/assets/javascripts/accounts_audio_profile.js +++ b/web/app/assets/javascripts/accounts_audio_profile.js @@ -13,6 +13,8 @@ userId = data.id; registerFtueSuccess(); + + $('#account-audio-content-scroller table tbody').html(''); } function afterShow(data) { From 8dc8e99a3b9dcafcf70dda24e84d9424e920a446 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 2 Mar 2014 15:58:12 -0500 Subject: [PATCH 06/15] VRFS-604 show invalid profiles on main account screen --- web/app/assets/javascripts/accounts.js | 17 +++++++++++++++-- .../javascripts/accounts_audio_profile.js | 4 ++-- web/app/views/clients/_account.html.erb | 3 ++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/web/app/assets/javascripts/accounts.js b/web/app/assets/javascripts/accounts.js index c01cb12ed..2cc32f091 100644 --- a/web/app/assets/javascripts/accounts.js +++ b/web/app/assets/javascripts/accounts.js @@ -28,15 +28,28 @@ var audioProfiles = prettyPrintAudioProfiles(context.jamClient.TrackGetDevices()); + var badAudioConfigs = []; + var allAudioConfigs = context.jamClient.FTUEGetAllAudioConfigurations(); + var goodAudioConfigs = context.jamClient.FTUEGetGoodAudioConfigurations(); + + for (var i=0; i < allAudioConfigs.length; i++) { + if ($.inArray(allAudioConfigs[i], goodAudioConfigs) === -1) { + badAudioConfigs.push(allAudioConfigs[i]); + } + } + var template = context.JK.fillTemplate($('#template-account-main').html(), { email: userDetail.email, name: userDetail.name, location : userDetail.location, instruments : prettyPrintInstruments(userDetail.instruments), photoUrl : context.JK.resolveAvatarUrl(userDetail.photo_url), - profiles : audioProfiles + validProfiles : audioProfiles, + invalidProfiles : badAudioConfigs.length > 0 ? badAudioConfigs.join(", ") : "N/A" }); - $('#account-content-scroller').html(template ); + $('#account-content-scroller').html(template); + + badAudioConfigs.join(", ") } function prettyPrintAudioProfiles(devices) { diff --git a/web/app/assets/javascripts/accounts_audio_profile.js b/web/app/assets/javascripts/accounts_audio_profile.js index 868452660..086d0cc18 100644 --- a/web/app/assets/javascripts/accounts_audio_profile.js +++ b/web/app/assets/javascripts/accounts_audio_profile.js @@ -13,8 +13,6 @@ userId = data.id; registerFtueSuccess(); - - $('#account-audio-content-scroller table tbody').html(''); } function afterShow(data) { @@ -32,6 +30,8 @@ function populateAccountAudio() { + $('#account-audio-content-scroller table tbody').html(''); + var badAudioConfigs = []; var allAudioConfigs = context.jamClient.FTUEGetAllAudioConfigurations(); var goodAudioConfigs = context.jamClient.FTUEGetGoodAudioConfigurations(); diff --git a/web/app/views/clients/_account.html.erb b/web/app/views/clients/_account.html.erb index 8409ae2ae..b9baa122f 100644 --- a/web/app/views/clients/_account.html.erb +++ b/web/app/views/clients/_account.html.erb @@ -106,7 +106,8 @@
From 57ea6134ff86f8b33f8489f60329e6893376bcac Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 2 Mar 2014 16:44:36 -0500 Subject: [PATCH 07/15] VRFS-1254 clip long names for sidebar --- web/app/assets/javascripts/sidebar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/app/assets/javascripts/sidebar.js b/web/app/assets/javascripts/sidebar.js index 79204b04e..5c085f6a0 100644 --- a/web/app/assets/javascripts/sidebar.js +++ b/web/app/assets/javascripts/sidebar.js @@ -101,7 +101,7 @@ userId: val.id, cssClass: css, avatar_url: context.JK.resolveAvatarUrl(val.photo_url), - userName: val.name, + userName: val.name.length > 20 ? val.name.substring(0,20) + "..." : val.name, status: val.online ? 'Available' : 'Offline', extra_info: '', hoverAction: val.musician ? "musician" : "fan", From 9a1bba988bdbe408daf3f36021f19c9eca29467b Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 2 Mar 2014 17:00:11 -0500 Subject: [PATCH 08/15] VRFS-604 show disconnected devices in FTUE --- web/app/assets/javascripts/accounts.js | 12 ++--------- .../javascripts/accounts_audio_profile.js | 18 ++++------------- .../assets/javascripts/createSession.js.erb | 2 +- web/app/assets/javascripts/ftue.js | 19 +++++++++++++++--- web/app/assets/javascripts/utils.js | 20 ++++++++++++++++++- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/web/app/assets/javascripts/accounts.js b/web/app/assets/javascripts/accounts.js index 2cc32f091..c8dc122d9 100644 --- a/web/app/assets/javascripts/accounts.js +++ b/web/app/assets/javascripts/accounts.js @@ -28,15 +28,7 @@ var audioProfiles = prettyPrintAudioProfiles(context.jamClient.TrackGetDevices()); - var badAudioConfigs = []; - var allAudioConfigs = context.jamClient.FTUEGetAllAudioConfigurations(); - var goodAudioConfigs = context.jamClient.FTUEGetGoodAudioConfigurations(); - - for (var i=0; i < allAudioConfigs.length; i++) { - if ($.inArray(allAudioConfigs[i], goodAudioConfigs) === -1) { - badAudioConfigs.push(allAudioConfigs[i]); - } - } + var badAudioConfigs = context.JK.getBadAudioConfigs(); var template = context.JK.fillTemplate($('#template-account-main').html(), { email: userDetail.email, @@ -49,7 +41,7 @@ }); $('#account-content-scroller').html(template); - badAudioConfigs.join(", ") + badAudioConfigs.join(", "); } function prettyPrintAudioProfiles(devices) { diff --git a/web/app/assets/javascripts/accounts_audio_profile.js b/web/app/assets/javascripts/accounts_audio_profile.js index 086d0cc18..853dec0b1 100644 --- a/web/app/assets/javascripts/accounts_audio_profile.js +++ b/web/app/assets/javascripts/accounts_audio_profile.js @@ -32,28 +32,18 @@ $('#account-audio-content-scroller table tbody').html(''); - var badAudioConfigs = []; - var allAudioConfigs = context.jamClient.FTUEGetAllAudioConfigurations(); - var goodAudioConfigs = context.jamClient.FTUEGetGoodAudioConfigurations(); + var badAudioConfigs = context.JK.getBadAudioConfigs(); - for (var i=0; i < allAudioConfigs.length; i++) { - console.log("allAudioConfigs[i]=%o", allAudioConfigs[i]); - if ($.inArray(allAudioConfigs[i], goodAudioConfigs) === -1) { - console.log("pushing %o onto badAudioConfigs", allAudioConfigs[i]); - badAudioConfigs.push(allAudioConfigs[i]); - } - } - - // render CONNECTED device profiles + // render valid device profiles var options = { - configurations: goodAudioConfigs, + configurations: context.JK.getGoodAudioConfigs(), valid: 1 } var template = context._.template($('#template-account-audio').html(), options, {variable: 'data'}); appendAudio(template); - // render DISCONNECTED device profiles + // render invalid device profiles options = { configurations: badAudioConfigs, valid: 0 diff --git a/web/app/assets/javascripts/createSession.js.erb b/web/app/assets/javascripts/createSession.js.erb index 16b8214dd..441585424 100644 --- a/web/app/assets/javascripts/createSession.js.erb +++ b/web/app/assets/javascripts/createSession.js.erb @@ -186,7 +186,7 @@ context.JK.GA.trackSessionMusicians(context.JK.GA.SessionCreationTypes.create); }, error: function() { - app.ajaxError(arguments); + app.notifyServerError(arguments0, "Unable to Create Session"); $('#btn-create-session').removeClass('button-disabled'); $('#btn-create-session').unbind('click', false); } diff --git a/web/app/assets/javascripts/ftue.js b/web/app/assets/javascripts/ftue.js index d090b7f91..86ae14cc8 100644 --- a/web/app/assets/javascripts/ftue.js +++ b/web/app/assets/javascripts/ftue.js @@ -465,9 +465,14 @@ ]; var optionsHtml = ''; var deviceOptionFunc = function (deviceKey, index, list) { - optionsHtml += ''; + optionsHtml += ''; }; + var badDeviceOptionFunc = function(deviceKey, index, list) { + optionsHtml += ''; + }; + + var badAudioConfigs = context.JK.getBadAudioConfigs(); + for (var i = 0; i < funcs.length; i++) { optionsHtml = ''; @@ -476,10 +481,11 @@ $select.empty(); var sortedDeviceKeys = context._.keys(devices).sort(); context._.each(sortedDeviceKeys, deviceOptionFunc); + context._.each(badAudioConfigs, badDeviceOptionFunc); $select.html(optionsHtml); context.JK.dropdown($select); $select.removeAttr("disabled"); - $('[layout-wizard-step="2"] .settings-asio select').removeAttr("disabled").easyDropDown('enable') + $('[layout-wizard-step="2"] .settings-asio select').removeAttr("disabled").easyDropDown('enable'); // Set selects to lowest possible values to start: $('#asio-framesize').val('2.5').change(); $('#asio-input-latency').val('0').change(); @@ -505,6 +511,12 @@ drivers[driverKey] + ''; }; + var badDeviceOptionFunc = function(deviceKey, index, list) { + optionsHtml += ''; + }; + + var badAudioConfigs = context.JK.getBadAudioConfigs(); + var optionsHtml = ''; var selectors = [ '[layout-wizard-step="0"] .settings-2-device select', @@ -513,6 +525,7 @@ ]; var sortedDeviceKeys = context._.keys(drivers).sort(); context._.each(sortedDeviceKeys, driverOptionFunc); + context._.each(badAudioConfigs, badDeviceOptionFunc); $.each(selectors, function (index, selector) { var $select = $(selector); $select.empty(); diff --git a/web/app/assets/javascripts/utils.js b/web/app/assets/javascripts/utils.js index 6ed8f2539..5392abc05 100644 --- a/web/app/assets/javascripts/utils.js +++ b/web/app/assets/javascripts/utils.js @@ -642,7 +642,25 @@ var result = context.jamClient.FTUEGetGoodConfigurationList(); console.log("hasOneConfiguredDevice: ", result); return result.length > 0; - } + }; + + context.JK.getGoodAudioConfigs = function() { + return context.jamClient.FTUEGetGoodAudioConfigurations(); + }; + + context.JK.getBadAudioConfigs = function() { + var badAudioConfigs = []; + var allAudioConfigs = context.jamClient.FTUEGetAllAudioConfigurations(); + var goodAudioConfigs = context.JK.getGoodAudioConfigs(); + + for (var i=0; i < allAudioConfigs.length; i++) { + if ($.inArray(allAudioConfigs[i], goodAudioConfigs) === -1) { + badAudioConfigs.push(allAudioConfigs[i]); + } + } + + return badAudioConfigs; + }; /* From 4e032f583d6b57527ec6babe5ae3b40b57390522 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 2 Mar 2014 17:09:02 -0500 Subject: [PATCH 09/15] expose new JS bridge methods --- web/app/assets/javascripts/fakeJamClient.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/web/app/assets/javascripts/fakeJamClient.js b/web/app/assets/javascripts/fakeJamClient.js index 0039b4acf..3a1746378 100644 --- a/web/app/assets/javascripts/fakeJamClient.js +++ b/web/app/assets/javascripts/fakeJamClient.js @@ -140,6 +140,16 @@ return ['a']; } + function FTUEGetAllAudioConfigurations() { + return ['a']; + } + + function FTUEGetGoodAudioConfigurations() { + reutrn ['a']; + } + + function FTUEG + function RegisterVolChangeCallBack(functionName) { dbg('RegisterVolChangeCallBack'); } @@ -664,6 +674,8 @@ this.FTUEStartLatency = FTUEStartLatency; this.FTUEGetExpectedLatency = FTUEGetExpectedLatency; this.FTUEGetGoodConfigurationList = FTUEGetGoodConfigurationList; + this.FTUEGetAllAudioConfigurations = FTUEGetAllAudioConfigurations; + this.FTUEGetGoodAudioConfigurations = FTUEGetGoodAudioConfigurations; // Session this.SessionAddTrack = SessionAddTrack; From 19f011a3c8cce0308a24a19f0048c4dd11f4701b Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 2 Mar 2014 17:10:12 -0500 Subject: [PATCH 10/15] fix syntax errors --- web/app/assets/javascripts/fakeJamClient.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web/app/assets/javascripts/fakeJamClient.js b/web/app/assets/javascripts/fakeJamClient.js index 3a1746378..c5286a53f 100644 --- a/web/app/assets/javascripts/fakeJamClient.js +++ b/web/app/assets/javascripts/fakeJamClient.js @@ -145,11 +145,9 @@ } function FTUEGetGoodAudioConfigurations() { - reutrn ['a']; + return ['a']; } - function FTUEG - function RegisterVolChangeCallBack(functionName) { dbg('RegisterVolChangeCallBack'); } From 0b7e860bd132965b5289074eaa77e684a185c964 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Mon, 3 Mar 2014 00:50:32 +0000 Subject: [PATCH 11/15] VRFS-756 removed extranous args from ajaxError --- web/app/assets/javascripts/invitationDialog.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/app/assets/javascripts/invitationDialog.js.erb b/web/app/assets/javascripts/invitationDialog.js.erb index 875cfb704..c0b2a3794 100644 --- a/web/app/assets/javascripts/invitationDialog.js.erb +++ b/web/app/assets/javascripts/invitationDialog.js.erb @@ -106,7 +106,7 @@ } else { rest.createEmailInvitations(emails, $('#txt-message').val()) .error(function() { - app.ajaxError(arguments); + app.ajaxError(); app.layout.closeDialog('inviteUsers'); }).success(function() { app.notifyAlert('Invites sent', 'You sent '+emails.length.toString()+' email invites'); From f760fa1795ab5672f1f06fd7b8a33b1fd5beeefd Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Mon, 3 Mar 2014 00:51:06 +0000 Subject: [PATCH 12/15] VRFS-756 fixed broken tests --- .../api_invited_users_controller.rb | 10 +++- web/spec/requests/invited_users_api_spec.rb | 54 ++++++++----------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/web/app/controllers/api_invited_users_controller.rb b/web/app/controllers/api_invited_users_controller.rb index 3618dce56..87210a778 100644 --- a/web/app/controllers/api_invited_users_controller.rb +++ b/web/app/controllers/api_invited_users_controller.rb @@ -31,8 +31,16 @@ iu.save iu end + else + iu = InvitedUser.new + iu.sender = current_user + iu.save + @invited_users = [iu] + end + if err = @invited_users.detect {|iu| iu.errors.any? } + response.status = :unprocessable_entity + respond_with err end - respond_with @invited_users, :responder => ApiResponder, :location => invitations_url(@invited_users) end end diff --git a/web/spec/requests/invited_users_api_spec.rb b/web/spec/requests/invited_users_api_spec.rb index 199a406b7..8097453e2 100644 --- a/web/spec/requests/invited_users_api_spec.rb +++ b/web/spec/requests/invited_users_api_spec.rb @@ -25,17 +25,15 @@ describe "Invited Users API ", :type => :api do end it "create with no note" do - post '/api/invited_users.json', {:email => 'tester@jamkazam.com'}.to_json, "CONTENT_TYPE" => 'application/json' - last_response.status.should eql(201) + post '/api/invited_users.json', {:emails => ['tester@jamkazam.com']}.to_json, "CONTENT_TYPE" => 'application/json' + last_response.status.should eql(200) UserMailer.deliveries.length.should == 1 - # now fetch it's data - location_header = last_response.headers["Location"] - get location_header - # parse json and test - body = JSON.parse(last_response.body) + bodies = JSON.parse(last_response.body) + expect(bodies.size).to eq(1) + body = bodies[0] body["id"].should_not be_nil body["created_at"].should_not be_nil body["email"].should == "tester@jamkazam.com" @@ -44,14 +42,12 @@ describe "Invited Users API ", :type => :api do end it "create with a note" do - post '/api/invited_users.json', {:email => 'tester@jamkazam.com', :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' - last_response.status.should eql(201) + post '/api/invited_users.json', {:emails => ['tester@jamkazam.com'], :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' + last_response.status.should eql(200) - # now fetch it's data - location_header = last_response.headers["Location"] - get location_header - - body = JSON.parse(last_response.body) + bodies = JSON.parse(last_response.body) + expect(bodies.length).to eq(1) + body = bodies[0] body["id"].should_not be_nil body["created_at"].should_not be_nil body["email"].should == "tester@jamkazam.com" @@ -63,7 +59,7 @@ describe "Invited Users API ", :type => :api do user.can_invite = false user.save - post '/api/invited_users.json', {:email => 'tester@jamkazam.com', :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' + post '/api/invited_users.json', {:emails => ['tester@jamkazam.com'], :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should eql(422) body = JSON.parse(last_response.body) body["errors"].should_not be_nil @@ -79,7 +75,7 @@ describe "Invited Users API ", :type => :api do end it "cant create with blank email" do - post '/api/invited_users.json', {:email => "", :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' + post '/api/invited_users.json', {:emails => [""], :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should eql(422) body = JSON.parse(last_response.body) body["errors"].should_not be_nil @@ -87,7 +83,7 @@ describe "Invited Users API ", :type => :api do end it "cant create with invalid email" do - post '/api/invited_users.json', {:email => "blurp", :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' + post '/api/invited_users.json', {:emails => ["blurp"], :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should eql(422) body = JSON.parse(last_response.body) body["errors"].should_not be_nil @@ -95,14 +91,12 @@ describe "Invited Users API ", :type => :api do end it "list" do - post '/api/invited_users.json', {:email => "tester@jamkazam.com", :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' - last_response.status.should eql(201) + post '/api/invited_users.json', {:emails => ["tester@jamkazam.com"], :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' + last_response.status.should eql(200) - # now fetch it's data - location_header = last_response.headers["Location"] - get location_header - - body = JSON.parse(last_response.body) + bodies = JSON.parse(last_response.body) + expect(bodies.length).to eq(1) + body = bodies[0] id = body["id"] get '/api/invited_users.json', "CONTENT_TYPE" => 'application/json' @@ -115,14 +109,12 @@ describe "Invited Users API ", :type => :api do end it "show" do - post '/api/invited_users.json', {:email => "tester@jamkazam.com", :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' - last_response.status.should eql(201) + post '/api/invited_users.json', {:emails => ["tester@jamkazam.com"], :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json' + last_response.status.should eql(200) - # now fetch it's data - location_header = last_response.headers["Location"] - get location_header - - body = JSON.parse(last_response.body) + bodies = JSON.parse(last_response.body) + expect(bodies.length).to eq(1) + body = bodies[0] id = body["id"] get "/api/invited_users/#{id}.json", "CONTENT_TYPE" => 'application/json' From 1e8d2bb724b60034a8905beeb865470c067d0bb3 Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Sun, 2 Mar 2014 23:16:48 -0600 Subject: [PATCH 13/15] update user with connection address on login or reconnect; make the better test data useable; fix up tests for geo stuff --- .gitignore | 4 +- ruby/lib/jam_ruby/connection_manager.rb | 17 +++++-- ruby/lib/jam_ruby/models/jam_isp.rb | 8 ++++ .../jam_ruby/models/geo_ip_blocks_spec.rb | 38 +++++++++------ .../jam_ruby/models/geo_ip_locations_spec.rb | 44 +++++++++--------- ruby/spec/jam_ruby/models/jam_isp_spec.rb | 46 ++++++++----------- ruby/spec/spec_helper.rb | 6 +-- .../lib/jam_websockets/router.rb | 26 ++++++++++- 8 files changed, 116 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index 40e3510c7..a1b1f7199 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ */vendor/cache HTML .DS_Store -coverage/ +coverage +update2 + diff --git a/ruby/lib/jam_ruby/connection_manager.rb b/ruby/lib/jam_ruby/connection_manager.rb index 91368427c..8b21b2767 100644 --- a/ruby/lib/jam_ruby/connection_manager.rb +++ b/ruby/lib/jam_ruby/connection_manager.rb @@ -44,7 +44,7 @@ module JamRuby end # reclaim the existing connection, if ip_address is not nil then perhaps a new address as well - def reconnect(conn, reconnect_music_session_id, ip_address) + def reconnect(conn, reconnect_music_session_id, ip_address, &blk) music_session_id = nil reconnected = false @@ -55,7 +55,7 @@ module JamRuby music_session_id_expression = "(CASE WHEN music_session_id='#{reconnect_music_session_id}' THEN music_session_id ELSE NULL END)" end - if ip_address + if ip_address and !ip_address.eql?(conn.ip_address) # turn ip_address string into a number, then fetch the isp and block records and update location info addr = JamIsp.ip_to_num(ip_address) @@ -71,6 +71,7 @@ module JamRuby location = GeoIpLocations.lookup(locid) if location.nil? + # todo what's a better default location? locidispid = 0 latitude = 0.0 longitude = 0.0 @@ -87,6 +88,7 @@ module JamRuby end conn.ip_address = ip_address + conn.addr = addr conn.locidispid = locidispid conn.latitude = latitude conn.longitude = longitude @@ -94,6 +96,9 @@ module JamRuby conn.region = region conn.city = city conn.save!(validate: false) + + # we're passing all this stuff so that the user record might be updated as well... + blk.call(addr, locidispid, latitude, longitude, countrycode, region, city) unless blk.nil? end sql =< %w[instruments genres icecast_server_groups] } - DatabaseCleaner.clean_with(:truncation, {:except => %w[instruments genres icecast_server_groups] }) + DatabaseCleaner.strategy = :truncation, {:except => %w[instruments genres icecast_server_groups jamcompany jamisp geoipblocks geoipisp geoiplocations] } + DatabaseCleaner.clean_with(:truncation, {:except => %w[instruments genres icecast_server_groups jamcompany jamisp geoipblocks geoipisp geoiplocations] }) end config.before(:each) do diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index d41eb05e2..ab77d4e99 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -485,7 +485,19 @@ module JamWebsockets context = nil ConnectionManager.active_record_transaction do |connection_manager| - music_session_id, reconnected = connection_manager.reconnect(connection, reconnect_music_session_id, remote_ip) + music_session_id, reconnected = connection_manager.reconnect(connection, reconnect_music_session_id, remote_ip) do |addr, locidispid, latitude, longitude, countrycode, region, city| + # update user + user.ip_address = remote_ip + user.addr = addr + user.locidispid = locidispid + user.lat = latitude + user.lng = longitude + user.country = countrycode + user.state = region + user.city = city + user.save!(validate: false) + end + context = @client_lookup[client_id] if music_session_id.nil? # if this is a reclaim of a connection, but music_session_id comes back null, then we need to check if this connection was IN a music session before. @@ -522,7 +534,17 @@ module JamWebsockets unless connection # log this connection in the database ConnectionManager.active_record_transaction do |connection_manager| - connection_manager.create_connection(user.id, client.client_id, remote_ip) do |conn, count| + connection_manager.create_connection(user.id, client.client_id, remote_ip) do |conn, count, addr, locidispid, latitude, longitude, countrycode, region, city| + # first update the user record with the current location + user.addr = addr + user.locidispid = locidispid + user.lat = latitude + user.lng = longitude + user.country = countrycode + user.state = region + user.city = city; + user.save! + if count == 1 Notification.send_friend_update(user.id, true, conn) end From ab1143c9a862155c51a50e215dd84c3f2808dfae Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Mon, 3 Mar 2014 14:31:25 -0600 Subject: [PATCH 14/15] fix and test user updates upon login --- ruby/spec/jam_ruby/connection_manager_spec.rb | 51 ++++++++++++++++--- ruby/spec/jam_ruby/models/get_work_spec.rb | 11 ++-- .../lib/jam_websockets/router.rb | 4 +- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/ruby/spec/jam_ruby/connection_manager_spec.rb b/ruby/spec/jam_ruby/connection_manager_spec.rb index 88672dec2..374d09d84 100644 --- a/ruby/spec/jam_ruby/connection_manager_spec.rb +++ b/ruby/spec/jam_ruby/connection_manager_spec.rb @@ -48,6 +48,10 @@ describe ConnectionManager do it "can't create two client_ids of same value" do client_id = "client_id1" user_id = create_user("test", "user1", "user1@jamkazam.com") + user = User.find(user_id) + user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user) + user.save! + user = nil @connman.create_connection(user_id, client_id, "1.1.1.1") expect { @connman.create_connection(user_id, client_id, "1.1.1.1") }.to raise_error(PG::Error) @@ -56,23 +60,58 @@ describe ConnectionManager do it "create connection then delete it" do client_id = "client_id2" - user_id = create_user("test", "user2", "user2@jamkazam.com") - count = @connman.create_connection(user_id, client_id, "1.1.1.1") + #user_id = create_user("test", "user2", "user2@jamkazam.com") + user = FactoryGirl.create(:user) + + count = @connman.create_connection(user.id, client_id, "1.1.1.1") { |conn, count, addr, locidispid, latitude, longitude, countrycode, region, city| + # first update the user record with the current location + u = User.find(user.id) + u.addr = addr + u.locidispid = locidispid + u.lat = latitude + u.lng = longitude + u.country = countrycode + u.state = region + u.city = city; + u.save! + u = nil + } + count.should == 1 + # make sure the connection is seen - @conn.exec("SELECT count(*) FROM connections where user_id = $1", [user_id]) do |result| - result.getvalue(0, 0).should == "1" + @conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result| + result.getvalue(0, 0).to_i.should == 1 end cc = Connection.find_by_client_id!(client_id) cc.connected?.should be_true + cc.ip_address.should eql("1.1.1.1") + cc.addr.should == 0x01010101 + cc.locidispid == 0 + cc.latitude.should == 30.2076 + cc.longitude.should == -97.8587 + cc.city.should eql('Austin') + cc.region.should eql('TX') + cc.countrycode.should eql('US') + + x = User.find(user.id) + #x.ip_address.should eql("1.1.1.1") + x.addr.should == 0x01010101 + x.locidispid == 0 + x.lat.should == 30.2076 + x.lng.should == -97.8587 + x.city.should eql('Austin') + x.state.should eql('TX') + x.country.should eql('US') + x = nil count = @connman.delete_connection(client_id) count.should == 0 - @conn.exec("SELECT count(*) FROM connections where user_id = $1", [user_id]) do |result| - result.getvalue(0, 0).should == "0" + @conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result| + result.getvalue(0, 0).to_i.should == 0 end end diff --git a/ruby/spec/jam_ruby/models/get_work_spec.rb b/ruby/spec/jam_ruby/models/get_work_spec.rb index 015d1e6a3..15b6d0e0a 100644 --- a/ruby/spec/jam_ruby/models/get_work_spec.rb +++ b/ruby/spec/jam_ruby/models/get_work_spec.rb @@ -2,19 +2,14 @@ require 'spec_helper' describe GetWork do - before(:each) do - - end - it "get_work_1" do - x = GetWork.get_work(1) - puts x.inspect + x = GetWork.get_work(0) x.should be_nil end it "get_work_list_1" do - x = GetWork.get_work_list(1) - puts x.inspect + x = GetWork.get_work_list(0) x.should eql([]) end + end \ No newline at end of file diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index ab77d4e99..91cc68623 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -487,7 +487,7 @@ module JamWebsockets ConnectionManager.active_record_transaction do |connection_manager| music_session_id, reconnected = connection_manager.reconnect(connection, reconnect_music_session_id, remote_ip) do |addr, locidispid, latitude, longitude, countrycode, region, city| # update user - user.ip_address = remote_ip + #user.ip_address = remote_ip user.addr = addr user.locidispid = locidispid user.lat = latitude @@ -543,7 +543,7 @@ module JamWebsockets user.country = countrycode user.state = region user.city = city; - user.save! + user.save!(validation: false) if count == 1 Notification.send_friend_update(user.id, true, conn) From 6ee68e89438ca0245bde88d1932c954eab31dc8a Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Mon, 3 Mar 2014 14:54:07 -0600 Subject: [PATCH 15/15] fix the login test for locidispid and add a test for reconnect --- ruby/spec/jam_ruby/connection_manager_spec.rb | 100 +++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/ruby/spec/jam_ruby/connection_manager_spec.rb b/ruby/spec/jam_ruby/connection_manager_spec.rb index 374d09d84..7161a4e94 100644 --- a/ruby/spec/jam_ruby/connection_manager_spec.rb +++ b/ruby/spec/jam_ruby/connection_manager_spec.rb @@ -58,7 +58,7 @@ describe ConnectionManager do end it "create connection then delete it" do - + client_id = "client_id2" #user_id = create_user("test", "user2", "user2@jamkazam.com") user = FactoryGirl.create(:user) @@ -89,7 +89,7 @@ describe ConnectionManager do cc.connected?.should be_true cc.ip_address.should eql("1.1.1.1") cc.addr.should == 0x01010101 - cc.locidispid == 0 + cc.locidispid.should == 17192000002 cc.latitude.should == 30.2076 cc.longitude.should == -97.8587 cc.city.should eql('Austin') @@ -99,7 +99,7 @@ describe ConnectionManager do x = User.find(user.id) #x.ip_address.should eql("1.1.1.1") x.addr.should == 0x01010101 - x.locidispid == 0 + x.locidispid.should == 17192000002 x.lat.should == 30.2076 x.lng.should == -97.8587 x.city.should eql('Austin') @@ -115,6 +115,100 @@ describe ConnectionManager do end end + it "create connection, reconnect, then delete it" do + + client_id = "client_id3" + #user_id = create_user("test", "user2", "user2@jamkazam.com") + user = FactoryGirl.create(:user) + + count = @connman.create_connection(user.id, client_id, "1.1.1.1") { |conn, count, addr, locidispid, latitude, longitude, countrycode, region, city| + # first update the user record with the current location + u = User.find(user.id) + u.addr = addr + u.locidispid = locidispid + u.lat = latitude + u.lng = longitude + u.country = countrycode + u.state = region + u.city = city + u.save! + u = nil + } + + count.should == 1 + + # make sure the connection is seen + + @conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result| + result.getvalue(0, 0).to_i.should == 1 + end + + cc = Connection.find_by_client_id!(client_id) + cc.connected?.should be_true + cc.ip_address.should eql("1.1.1.1") + cc.addr.should == 0x01010101 + cc.locidispid.should == 17192000002 + cc.latitude.should == 30.2076 + cc.longitude.should == -97.8587 + cc.city.should eql('Austin') + cc.region.should eql('TX') + cc.countrycode.should eql('US') + + x = User.find(user.id) + #x.ip_address.should eql("1.1.1.1") + x.addr.should == 0x01010101 + x.locidispid.should == 17192000002 + x.lat.should == 30.2076 + x.lng.should == -97.8587 + x.city.should eql('Austin') + x.state.should eql('TX') + x.country.should eql('US') + x = nil + + @connman.reconnect(cc, nil, "33.1.2.3") { |addr, locidispid, latitude, longitude, countrycode, region, city| + # first update the user record with the current location + u = User.find(user.id) + u.addr = addr + u.locidispid = locidispid + u.lat = latitude + u.lng = longitude + u.country = countrycode + u.state = region + u.city = city + u.save! + u = nil + } + + cc = Connection.find_by_client_id!(client_id) + cc.connected?.should be_true + cc.ip_address.should eql("33.1.2.3") + cc.addr.should == 0x21010203 + cc.locidispid.should == 30350000003 + cc.latitude.should == 29.7633 + cc.longitude.should == -95.3633 + cc.city.should eql('Houston') + cc.region.should eql('TX') + cc.countrycode.should eql('US') + + x = User.find(user.id) + #x.ip_address.should eql("33.1.2.3") + x.addr.should == 0x21010203 + x.locidispid.should == 30350000003 + x.lat.should == 29.7633 + x.lng.should == -95.3633 + x.city.should eql('Houston') + x.state.should eql('TX') + x.country.should eql('US') + x = nil + + count = @connman.delete_connection(client_id) + count.should == 0 + + @conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result| + result.getvalue(0, 0).to_i.should == 0 + end + end + # it "create connection creates user joined message appropriately" do # client_id = "client_id3"