Fix tests to use rspec expect syntax

This commit is contained in:
cn 2016-11-30 22:07:51 +01:00
parent f76c5933d7
commit 7ce1c1f480
2 changed files with 51 additions and 54 deletions

View File

@ -28,149 +28,150 @@ describe Dyndnsd::Daemon do
it 'requires authentication' do it 'requires authentication' do
get '/' get '/'
last_response.status.should == 401 expect(last_response.status).to eq(401)
pending 'Need to find a way to add custom body on 401 responses' pending 'Need to find a way to add custom body on 401 responses'
last_response.should be_ok 'badauth' expect(last_response).not_to be_ok
expect(last_response.body).to eq('badauth')
end end
it 'only supports GET requests' do it 'only supports GET requests' do
authorize 'test', 'secret' authorize 'test', 'secret'
post '/nic/update' post '/nic/update'
last_response.status.should == 405 expect(last_response.status).to eq(405)
end end
it 'provides only the /nic/update URL' do it 'provides only the /nic/update URL' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/other/url' get '/other/url'
last_response.status.should == 404 expect(last_response.status).to eq(404)
end end
it 'requires the hostname query parameter' do it 'requires the hostname query parameter' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/nic/update' get '/nic/update'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'notfqdn' expect(last_response.body).to eq('notfqdn')
end end
it 'supports multiple hostnames in request' do it 'supports multiple hostnames in request' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=1.2.3.4' get '/nic/update?hostname=foo.example.org,bar.example.org&myip=1.2.3.4'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == "good 1.2.3.4\ngood 1.2.3.4" expect(last_response.body).to eq("good 1.2.3.4\ngood 1.2.3.4")
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=2001:db8::1' get '/nic/update?hostname=foo.example.org,bar.example.org&myip=2001:db8::1'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == "good 2001:db8::1\ngood 2001:db8::1" expect(last_response.body).to eq("good 2001:db8::1\ngood 2001:db8::1")
end end
it 'rejects request if one hostname is invalid' do it 'rejects request if one hostname is invalid' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/nic/update?hostname=test' get '/nic/update?hostname=test'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'notfqdn' expect(last_response.body).to eq('notfqdn')
get '/nic/update?hostname=test.example.com' get '/nic/update?hostname=test.example.com'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'notfqdn' expect(last_response.body).to eq('notfqdn')
get '/nic/update?hostname=test.example.org.me' get '/nic/update?hostname=test.example.org.me'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'notfqdn' expect(last_response.body).to eq('notfqdn')
get '/nic/update?hostname=foo.test.example.org' get '/nic/update?hostname=foo.test.example.org'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'notfqdn' expect(last_response.body).to eq('notfqdn')
get '/nic/update?hostname=in%20valid.example.org' get '/nic/update?hostname=in%20valid.example.org'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'notfqdn' expect(last_response.body).to eq('notfqdn')
get '/nic/update?hostname=valid.example.org,in.valid.example.org' get '/nic/update?hostname=valid.example.org,in.valid.example.org'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'notfqdn' expect(last_response.body).to eq('notfqdn')
end end
it 'rejects request if user does not own one hostname' do it 'rejects request if user does not own one hostname' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/nic/update?hostname=notmyhost.example.org' get '/nic/update?hostname=notmyhost.example.org'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'nohost' expect(last_response.body).to eq('nohost')
get '/nic/update?hostname=foo.example.org,notmyhost.example.org' get '/nic/update?hostname=foo.example.org,notmyhost.example.org'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'nohost' expect(last_response.body).to eq('nohost')
end end
it 'updates a host on IP change' do it 'updates a host on IP change' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4' get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
last_response.should be_ok expect(last_response).to be_ok
get '/nic/update?hostname=foo.example.org&myip=1.2.3.40' get '/nic/update?hostname=foo.example.org&myip=1.2.3.40'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'good 1.2.3.40' expect(last_response.body).to eq('good 1.2.3.40')
get '/nic/update?hostname=foo.example.org&myip=2001:db8::1' get '/nic/update?hostname=foo.example.org&myip=2001:db8::1'
last_response.should be_ok expect(last_response).to be_ok
get '/nic/update?hostname=foo.example.org&myip=2001:db8::10' get '/nic/update?hostname=foo.example.org&myip=2001:db8::10'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'good 2001:db8::10' expect(last_response.body).to eq('good 2001:db8::10')
end end
it 'returns IP no change' do it 'returns IP no change' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4' get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
last_response.should be_ok expect(last_response).to be_ok
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4' get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'nochg 1.2.3.4' expect(last_response.body).to eq('nochg 1.2.3.4')
get '/nic/update?hostname=foo.example.org&myip=2001:db8::1' get '/nic/update?hostname=foo.example.org&myip=2001:db8::1'
last_response.should be_ok expect(last_response).to be_ok
get '/nic/update?hostname=foo.example.org&myip=2001:db8::1' get '/nic/update?hostname=foo.example.org&myip=2001:db8::1'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'nochg 2001:db8::1' expect(last_response.body).to eq('nochg 2001:db8::1')
end end
it 'outputs IP status per hostname' do it 'outputs IP status per hostname' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4' get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'good 1.2.3.4' expect(last_response.body).to eq('good 1.2.3.4')
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=1.2.3.4' get '/nic/update?hostname=foo.example.org,bar.example.org&myip=1.2.3.4'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == "nochg 1.2.3.4\ngood 1.2.3.4" expect(last_response.body).to eq("nochg 1.2.3.4\ngood 1.2.3.4")
get '/nic/update?hostname=foo.example.org&myip=2001:db8::1' get '/nic/update?hostname=foo.example.org&myip=2001:db8::1'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'good 2001:db8::1' expect(last_response.body).to eq('good 2001:db8::1')
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=2001:db8::1' get '/nic/update?hostname=foo.example.org,bar.example.org&myip=2001:db8::1'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == "nochg 2001:db8::1\ngood 2001:db8::1" expect(last_response.body).to eq("nochg 2001:db8::1\ngood 2001:db8::1")
end end
it 'uses clients remote IP address if myip not specified' do it 'uses clients remote IP address if myip not specified' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/nic/update?hostname=foo.example.org' get '/nic/update?hostname=foo.example.org'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'good 127.0.0.1' expect(last_response.body).to eq('good 127.0.0.1')
end end
it 'uses clients remote IP address from X-Real-IP header if behind proxy' do it 'uses clients remote IP address from X-Real-IP header if behind proxy' do
authorize 'test', 'secret' authorize 'test', 'secret'
get '/nic/update?hostname=foo.example.org', '', 'HTTP_X_REAL_IP' => '10.0.0.1' get '/nic/update?hostname=foo.example.org', '', 'HTTP_X_REAL_IP' => '10.0.0.1'
last_response.should be_ok expect(last_response).to be_ok
last_response.body.should == 'good 10.0.0.1' expect(last_response.body).to eq('good 10.0.0.1')
end end
end end

View File

@ -6,7 +6,3 @@ require 'rack/test'
require 'dyndnsd' require 'dyndnsd'
require 'support/dummy_database' require 'support/dummy_database'
require 'support/dummy_updater' require 'support/dummy_updater'
RSpec.configure do |config|
config.expect_with(:rspec) { |c| c.syntax = :should }
end