spec/whm/server_spec.rb in lumberg-1.0.0 vs spec/whm/server_spec.rb in lumberg-1.0.1
- old
+ new
@@ -1,8 +1,8 @@
require 'spec_helper'
-# Requests will need an "Authorization" header with
+# Requests will need an "Authorization" header with
# WHM username:hash"
module Lumberg
describe Whm::Server do
before(:each) do
@login = { :host => @whm_host, :hash => @whm_hash }
@@ -26,10 +26,19 @@
it "should allow setting of the username" do
@whm = Whm::Server.new(@login.merge(:user => 'bob'))
@whm.user.should == 'bob'
end
+
+ it "should default to false for basic_auth" do
+ @whm.basic_auth.should be_false
+ end
+
+ it "should allow setting of basic_auth" do
+ @whm = Whm::Server.new(@login.merge(:basic_auth => true))
+ @whm.basic_auth.should be_true
+ end
end
describe "#format_url" do
it "converts the host into an SSL URL by default" do
@whm.send(:format_url).should == "https://myhost.com:2087/json-api/"
@@ -46,11 +55,11 @@
end
end
describe "#format_hash" do
it "raises an error if hash is not a string" do
- expect{ Whm::Server.new(:host => @whm_host, :hash => nil) }.to
+ expect{ Whm::Server.new(:host => @whm_host, :hash => nil) }.to
raise_error(Lumberg::WhmArgumentError, "Missing WHM hash")
end
it "removes \\n's from the hash" do
hash = "my\nhash\n\n\n\n"
@@ -62,11 +71,11 @@
hash = " my hash "
@whm = Whm::Server.new(:host => @whm_host, :hash => hash)
@whm.hash.should == 'myhash'
end
end
-
+
describe "#perform_request" do
# These tests are skipped when running against
# a real WHM server
unless live_test?
describe "my_function" do
@@ -277,12 +286,121 @@
it "caches @vars" do
Whm.should_receive(:const_get).once.and_return(Whm::Account)
@whm.account
@whm.account
end
-
+
it "raises to super" do
expect { @whm.asdf }.to raise_error(NoMethodError)
+ end
+ end
+
+ describe "#prepare_request" do
+ context "when @basic_auth is true" do
+ before do
+ @whm.basic_auth = true
+ @req = @whm.instance_eval {
+ prepare_request(URI.parse("http://example.com/"))
+ }
+ end
+
+ it "sets Authorization header to 'Basic {base64text}'" do
+ test_auth = Base64.encode64("#{@whm.user}:#{@whm.hash}")
+ auth = @req['Authorization']
+ auth.should_not be_nil
+ auth.should == "Basic #{test_auth}"
+ end
+ end
+
+ context "when @basic_auth is false" do
+ before do
+ @req = @whm.instance_eval {
+ prepare_request(URI.parse("http://example.com/"))
+ }
+ end
+ it "sets Authorization header to 'WHM user:hash'" do
+ test_auth = "#{@whm.user}:#{@whm.hash}"
+ auth = @req['Authorization']
+ auth.should_not be_nil
+ auth.should == "WHM #{test_auth}"
+ end
+ end
+ end
+
+ describe "#list_ips" do
+ use_vcr_cassette "whm/server/listips"
+
+ it "lists all the ip addresses" do
+ result = @whm.list_ips
+ result[:params][0][:ip].should == "123.123.123.123"
+ result[:params][0][:used].should == 1
+ result[:params].should have(242).ips
+ end
+ end
+
+ describe "#add_ip" do
+ use_vcr_cassette "whm/server/addip"
+
+ it "requires an ip address" do
+ requires_attr('ip') { @whm.add_ip(:netmask => '255.255.255.250') }
+ end
+
+ it "requires a netmask" do
+ requires_attr('netmask') { @whm.add_ip(:ip => '123.123.123.123') }
+ end
+
+ it "adds the ip address" do
+ result = @whm.add_ip(:ip => '208.77.188.166', :netmask => '255.255.255.0')
+ result[:success].should be_true
+ end
+ end
+
+ describe "#delete_ip" do
+ use_vcr_cassette "whm/server/delip"
+
+ it "requires an ip address" do
+ requires_attr('ip') { @whm.delete_ip }
+ end
+
+ it "deletes the ip address" do
+ result = @whm.delete_ip(:ip => '208.77.188.166')
+ result[:success].should be_true
+ end
+ end
+
+ describe "#set_hostname" do
+ use_vcr_cassette "whm/server/sethostname"
+
+ it "requires a hostname" do
+ requires_attr('hostname') { @whm.set_hostname }
+ end
+
+ it "changes the server's hostname" do
+ result = @whm.set_hostname(:hostname => "myhost.com")
+ result[:success].should be_true
+ end
+ end
+
+ describe "#set_resolvers" do
+ use_vcr_cassette "whm/server/setresolvers"
+
+ it "requires a nameserver1" do
+ requires_attr('nameserver1') { @whm.set_resolvers }
+ end
+
+ it "configures the nameservers" do
+ result = @whm.set_resolvers(:nameserver1 => "123.123.123.123", :nameserver2 => "123.123.123.124")
+ result[:success].should be_true
+ end
+ end
+
+ describe "#show_bandwidth" do
+ use_vcr_cassette "whm/server/showbw"
+
+ it "shows the bandwidth information" do
+ result = @whm.show_bandwidth(:year => 2011, :month => 5)
+ result[:params][:month].to_i.should == 5
+ result[:params][:acct].should have(3).accounts
end
end
end
end