Skip to content

Commit

Permalink
added tests for HTTP redirection and certificate download
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Aug 6, 2014
1 parent 2bfd838 commit 5cc2b39
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
23 changes: 22 additions & 1 deletion test/eula_downloader_spec.rb
Expand Up @@ -52,7 +52,7 @@

it "it raises an exception when download fails" do
index = Net::HTTPNotFound.new("1.1", 404, "Not Found")
index.should_receive(:body).and_return("")
expect(index).to receive(:body).and_return("")

Net::HTTP.any_instance.should_receive(:request).
with(an_instance_of(Net::HTTP::Get)).and_return(index)
Expand All @@ -67,6 +67,27 @@
expect(Dir.entries(tmpdir)).to match_array([".", ".."])
end
end

it "handles HTTP redirection" do
index1 = Net::HTTPRedirection.new("1.1", 302, "Found")
index1["location"] = "http://eulas.example.com/eula"

index2 = Net::HTTPSuccess.new("1.1", 200, "OK")
expect(index2).to receive(:body).and_return("")

http = double()
expect(Net::HTTP).to receive(:new).twice.and_return(http)
expect(http).to receive(:request).twice.and_return(index1, index2)

Dir.mktmpdir do |tmpdir|
loader = Registration::EulaDownloader.new("http://example.com/eula", tmpdir)

expect{loader.download}.not_to raise_error

# nothing saved
expect(Dir.entries(tmpdir)).to match_array([".", ".."])
end
end
end

end
19 changes: 18 additions & 1 deletion test/ssl_certificate_spec.rb
Expand Up @@ -23,9 +23,26 @@
it "loads SSL certificate from a file" do
expect(subject).to be_a(Registration::SslCertificate)
end
end

describe ".load" do
it "loads SSL certificate from data" do
expect(Registration::SslCertificate.load(File.read(fixtures_file("test.pem")))).to be_a(Registration::SslCertificate)
expect(Registration::SslCertificate.load(File.read(fixtures_file("test.pem")))).to \
be_a(Registration::SslCertificate)
end
end

describe ".download" do
it "downloads a SSL certificate from server" do
response = Net::HTTPSuccess.new("1.1", 200, "OK")
expect(response).to receive(:body).and_return(File.read(fixtures_file("test.pem")))

http = double()
expect(http).to receive(:request).and_return(response)
expect(Net::HTTP).to receive(:new).and_return(http)

expect(Registration::SslCertificate.download("http://example.com")).to \
be_a(Registration::SslCertificate)
end
end

Expand Down

0 comments on commit 5cc2b39

Please sign in to comment.