dyndnsd/spec/daemon_spec.rb

124 lines
3.3 KiB
Ruby
Raw Normal View History

2013-04-27 14:07:14 +02:00
require 'spec_helper'
describe Dyndnsd::Daemon do
include Rack::Test::Methods
def app
config = {
2013-04-27 14:59:25 +02:00
'domain' => 'example.org',
2013-04-27 14:07:14 +02:00
'users' => {
'test' => {
'password' => 'secret',
2013-04-27 15:20:08 +02:00
'hosts' => ['foo.example.org', 'bar.example.org']
2013-04-27 14:07:14 +02:00
}
}
}
db = Dyndnsd::DummyDatabase.new({})
updater = Dyndnsd::Updater::Dummy.new
2013-04-27 14:37:52 +02:00
responder = Dyndnsd::Responder::DynDNSStyle.new
2013-04-27 14:07:14 +02:00
app = Dyndnsd::Daemon.new(config, db, updater, responder)
Rack::Auth::Basic.new(app, "DynDNS") do |user,pass|
(config['users'].has_key? user) and (config['users'][user]['password'] == pass)
end
end
it 'requires authentication' do
get '/'
last_response.status.should == 401
2013-04-27 14:37:52 +02:00
pending 'Need to find a way to add custom body on 401 responses'
last_response.should be_ok 'badauth'
2013-04-27 14:07:14 +02:00
end
it 'only supports GET requests' do
authorize 'test', 'secret'
post '/nic/update'
last_response.status.should == 405
end
it 'provides only the /nic/update' do
authorize 'test', 'secret'
get '/other/url'
last_response.status.should == 404
end
it 'requires the hostname query parameter' do
authorize 'test', 'secret'
get '/nic/update'
2013-04-27 14:37:52 +02:00
last_response.should be_ok
last_response.body.should == 'notfqdn'
2013-04-27 14:07:14 +02:00
end
it 'forbids changing hosts a user does not own' do
authorize 'test', 'secret'
get '/nic/update?hostname=notmyhost.example.org'
2013-04-27 14:37:52 +02:00
last_response.should be_ok
last_response.body.should == 'nohost'
2013-04-27 14:07:14 +02:00
end
it 'updates a host on change' do
authorize 'test', 'secret'
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
last_response.should be_ok
2013-04-27 14:37:52 +02:00
get '/nic/update?hostname=foo.example.org&myip=1.2.3.40'
2013-04-27 14:07:14 +02:00
last_response.should be_ok
2013-04-27 14:37:52 +02:00
last_response.body.should == 'good 1.2.3.40'
2013-04-27 14:07:14 +02:00
end
it 'returns no change' do
authorize 'test', 'secret'
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
last_response.should be_ok
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
last_response.should be_ok
2013-04-27 14:37:52 +02:00
last_response.body.should == 'nochg 1.2.3.4'
2013-04-27 14:07:14 +02:00
end
it 'forbids invalid hostnames' do
2013-04-27 14:59:25 +02:00
authorize 'test', 'secret'
get '/nic/update?hostname=test'
last_response.should be_ok
last_response.body.should == 'notfqdn'
get '/nic/update?hostname=test.example.com'
last_response.should be_ok
last_response.body.should == 'notfqdn'
get '/nic/update?hostname=test.example.org.me'
last_response.should be_ok
last_response.body.should == 'notfqdn'
get '/nic/update?hostname=foo.test.example.org'
last_response.should be_ok
last_response.body.should == 'notfqdn'
get '/nic/update?hostname=in%20valid.example.org.me'
last_response.should be_ok
last_response.body.should == 'notfqdn'
2013-04-27 14:07:14 +02:00
end
2013-04-27 15:20:08 +02:00
it 'outputs status for hostname' do
authorize 'test', 'secret'
get '/nic/update?hostname=foo.example.org&myip=1.2.3.4'
last_response.should be_ok
last_response.body.should == 'good 1.2.3.4'
2013-04-27 14:07:14 +02:00
end
it 'supports multiple hostnames in request' do
2013-04-27 15:20:08 +02:00
authorize 'test', 'secret'
2013-04-27 14:07:14 +02:00
pending
2013-04-27 15:20:08 +02:00
get '/nic/update?hostname=foo.example.org,bar.example.org&myip=1.2.3.4'
last_response.should be_ok
last_response.body.should == "good 1.2.3.4\ngood 1.2.3.4"
2013-04-27 14:07:14 +02:00
end
end