Skip to content

Commit 5bb3d3c

Browse files
committed
chore: add specs for @sha256 flag
1 parent ae845cc commit 5bb3d3c

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

lib/bigbluebutton_api.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class BigBlueButtonApi
6969
# url:: URL to a BigBlueButton server (e.g. http://demo.bigbluebutton.org/bigbluebutton/api)
7070
# secret:: Shared secret for this server
7171
# version:: API version e.g. 0.81
72-
# logger::
72+
# logger:: Logger object to log actions (so apps can use their own loggers)
7373
# sha256:: Flag to use sha256 when hashing url contents for checksum
7474
def initialize(url, secret, version=nil, logger=nil, sha256=false)
7575
@supported_versions = ['0.8', '0.81', '0.9', '1.0']
@@ -79,6 +79,7 @@ def initialize(url, secret, version=nil, logger=nil, sha256=false)
7979
@request_headers = {} # http headers sent in all requests
8080
@logger = logger
8181
@sha256 = sha256
82+
# If logger is not informed, it defaults to STDOUT with INFO level
8283
if logger.nil?
8384
@logger = Logger.new(STDOUT)
8485
@logger.level = Logger::INFO

spec/bigbluebutton_api_spec.rb

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -474,17 +474,34 @@
474474
end
475475

476476
context "includes the checksum" do
477-
let(:params) { { :param1 => "value1", :param2 => "value2" } }
478-
let(:checksum) {
479-
# the hash can be sorted differently depending on the ruby version
480-
if params.map{ |k,v| k }.join =~ /^param1/
481-
"67882ae54f49600f56f358c10d24697ef7d8c6b2"
482-
else
483-
"85a54e28e4ec18bfdcb214a73f74d35b09a84176"
484-
end
485-
}
486-
subject { api.get_url(:join, params)[0] }
487-
it { subject.should match(/checksum=#{checksum}$/) }
477+
context "when @sha256 is false or nil" do
478+
let(:params) { { param1: "value1", param2: "value2" } }
479+
let(:checksum) {
480+
# the hash can be sorted differently depending on the ruby version
481+
if params.map{ |k, v| k }.join =~ /^param1/
482+
"67882ae54f49600f56f358c10d24697ef7d8c6b2"
483+
else
484+
"85a54e28e4ec18bfdcb214a73f74d35b09a84176"
485+
end
486+
}
487+
subject { api.get_url(:join, params)[0] }
488+
it('uses SHA1') { subject.should match(/checksum=#{checksum}$/) }
489+
end
490+
491+
context "when @sha256 flag is true" do
492+
let(:api) { BigBlueButton::BigBlueButtonApi.new(url, secret, version, logger, true) }
493+
let(:params) { { param1: "value1", param2: "value2" } }
494+
let(:checksum) {
495+
# the hash can be sorted differently depending on the ruby version
496+
if params.map{ |k,v| k }.join =~ /^param1/
497+
"0e7b1611809fad890a114dddae1a37fecf14c28971afc10ee3eac432da5b8b41"
498+
else
499+
"21bf2d24c27251c4b2b2f0d5dd4b966a2f16fbfc7882e102b44c6d67f728f0c8"
500+
end
501+
}
502+
subject { api.get_url(:join, params)[0] }
503+
it('uses SHA256') { subject.should match(/checksum=#{checksum}$/) }
504+
end
488505
end
489506
end
490507
end

0 commit comments

Comments
 (0)