|
226 | 226 | :userID => "id123", :webVoiceConf => 12345678, :createTime => 9876543 } |
227 | 227 | } |
228 | 228 |
|
229 | | - before { api.should_receive(:get_url).with(:join, params).and_return("test-url") } |
| 229 | + before { api.should_receive(:get_url).with(:join, params).and_return(["test-url", nil]) } |
230 | 230 | it { |
231 | 231 | options = { :userID => "id123", :webVoiceConf => 12345678, :createTime => 9876543 } |
232 | 232 | api.join_meeting_url("meeting-id", "Name", "pw", options).should == "test-url" |
|
409 | 409 | describe "#get_url" do |
410 | 410 |
|
411 | 411 | context "when method = :index" do |
412 | | - it { api.get_url(:index).should == api.url } |
| 412 | + it { api.get_url(:index).should == [api.url, nil] } |
413 | 413 | end |
414 | 414 |
|
415 | 415 | context "when method = :check" do |
416 | 416 | it { |
417 | 417 | api.url = 'http://my-test-server.com/bigbluebutton/api' |
418 | | - api.get_url(:check).should == 'http://my-test-server.com/check' |
| 418 | + api.get_url(:check).should == ['http://my-test-server.com/check', nil] |
419 | 419 | } |
420 | 420 | end |
421 | 421 |
|
422 | 422 | context "when method != :index" do |
423 | 423 | context "validates the entire url" do |
424 | 424 | context "with params" do |
425 | 425 | let(:params) { { :param1 => "value1", :param2 => "value2" } } |
426 | | - subject { api.get_url(:join, params) } |
| 426 | + subject { api.get_url(:join, params)[0] } |
427 | 427 | it { |
428 | 428 | # the hash can be sorted differently depending on the ruby version |
429 | 429 | if params.map{ |k,v| "#{k}" }.join =~ /^param1/ |
|
435 | 435 | end |
436 | 436 |
|
437 | 437 | context "without params" do |
438 | | - subject { api.get_url(:join) } |
| 438 | + subject { api.get_url(:join)[0] } |
439 | 439 | it { subject.should match(/#{url}\/join\?[^&]/) } |
440 | 440 | end |
441 | 441 | end |
442 | 442 |
|
| 443 | + context "when method = :setConfigXML" do |
| 444 | + it { |
| 445 | + api.url = 'http://my-test-server.com/bigbluebutton/api' |
| 446 | + response = api.get_url(:setConfigXML, { param1: 1, param2: 2 }) |
| 447 | + response[0].should eql('http://my-test-server.com/bigbluebutton/api/setConfigXML') |
| 448 | + response[1].should match(/checksum=.*¶m1=1¶m2=2/) |
| 449 | + } |
| 450 | + end |
| 451 | + |
443 | 452 | context "discards params with nil value" do |
444 | 453 | let(:params) { { :param1 => "value1", :param2 => nil } } |
445 | | - subject { api.get_url(:join, params) } |
| 454 | + subject { api.get_url(:join, params)[0] } |
446 | 455 | it { subject.should_not match(/param2=/) } |
447 | 456 | end |
448 | 457 |
|
449 | 458 | context "escapes all params" do |
450 | 459 | let(:params) { { :param1 => "value with spaces", :param2 => "@$" } } |
451 | | - subject { api.get_url(:join, params) } |
| 460 | + subject { api.get_url(:join, params)[0] } |
452 | 461 | it { subject.should match(/param1=value\+with\+spaces/) } |
453 | 462 | it { subject.should match(/param2=%40%24/) } |
454 | 463 | end |
455 | 464 |
|
| 465 | + [ [' ', '+'], |
| 466 | + ['*', '*'] |
| 467 | + ].each do |values| |
| 468 | + context "escapes #{values[0].inspect} as #{values[1].inspect}" do |
| 469 | + let(:params) { { param1: "before#{values[0]}after" } } |
| 470 | + subject { api.get_url(:join, params)[0] } |
| 471 | + it { subject.should match(/param1=before#{Regexp.quote(values[1])}after/) } |
| 472 | + end |
| 473 | + end |
| 474 | + |
456 | 475 | context "includes the checksum" do |
457 | 476 | let(:params) { { :param1 => "value1", :param2 => "value2" } } |
458 | 477 | let(:checksum) { |
459 | 478 | # the hash can be sorted differently depending on the ruby version |
460 | | - if params.map{ |k,v| "#{k}" }.join =~ /^param1/ |
| 479 | + if params.map{ |k,v| k }.join =~ /^param1/ |
461 | 480 | "67882ae54f49600f56f358c10d24697ef7d8c6b2" |
462 | 481 | else |
463 | 482 | "85a54e28e4ec18bfdcb214a73f74d35b09a84176" |
464 | 483 | end |
465 | 484 | } |
466 | | - subject { api.get_url(:join, params) } |
| 485 | + subject { api.get_url(:join, params)[0] } |
467 | 486 | it { subject.should match(/checksum=#{checksum}$/) } |
468 | 487 | end |
469 | 488 | end |
|
477 | 496 | let(:make_request) { api.send_api_request(method, params, data) } |
478 | 497 | let(:response_mock) { mock() } # mock of what send_request() would return |
479 | 498 |
|
480 | | - before { api.should_receive(:get_url).with(method, params).and_return(url) } |
| 499 | + before { api.should_receive(:get_url).with(method, params).and_return([url, nil]) } |
481 | 500 |
|
482 | 501 | context "returns an empty hash if the response body is empty" do |
483 | 502 | before do |
|
567 | 586 | let(:data) { "any data" } |
568 | 587 | before { |
569 | 588 | path = "/res?param1=value1&checksum=12345" |
570 | | - opts = { 'Content-Type' => 'text/xml' } |
| 589 | + opts = { 'Content-Type' => 'application/x-www-form-urlencoded' } |
571 | 590 | @http_mock.should_receive(:post).with(path, data, opts).and_return("ok") |
572 | 591 | } |
573 | 592 | it { |
|
589 | 608 | let(:data) { "any data" } |
590 | 609 | before { |
591 | 610 | path = "/res?param1=value1&checksum=12345" |
592 | | - opts = { 'Content-Type' => 'text/xml', :anything => "anything" } |
| 611 | + opts = { 'Content-Type' => 'application/x-www-form-urlencoded', :anything => "anything" } |
593 | 612 | @http_mock.should_receive(:post).with(path, data, opts).and_return("ok") |
594 | 613 | } |
595 | 614 | it { |
|
0 commit comments