mirror of
https://github.com/cmur2/dyndnsd.git
synced 2025-06-26 02:30:22 +02:00
Fiat lux
This commit is contained in:
87
spec/daemon_spec.rb
Normal file
87
spec/daemon_spec.rb
Normal file
@ -0,0 +1,87 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Dyndnsd::Daemon do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app
|
||||
config = {
|
||||
'users' => {
|
||||
'test' => {
|
||||
'password' => 'secret',
|
||||
'hosts' => ['foo.example.org']
|
||||
}
|
||||
}
|
||||
}
|
||||
db = Dyndnsd::DummyDatabase.new({})
|
||||
updater = Dyndnsd::Updater::Dummy.new
|
||||
responder = Dyndnsd::Responder::RestStyle.new
|
||||
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
|
||||
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'
|
||||
last_response.status.should == 422
|
||||
end
|
||||
|
||||
it 'forbids changing hosts a user does not own' do
|
||||
authorize 'test', 'secret'
|
||||
get '/nic/update?hostname=notmyhost.example.org'
|
||||
last_response.status.should == 403
|
||||
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
|
||||
|
||||
get '/nic/update?hostname=foo.example.org&myip=1.2.3.400'
|
||||
last_response.should be_ok
|
||||
last_response.body.should == 'Good'
|
||||
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
|
||||
last_response.body.should == 'No change'
|
||||
end
|
||||
|
||||
it 'forbids invalid hostnames' do
|
||||
pending
|
||||
end
|
||||
|
||||
it 'outputs status per hostname' do
|
||||
pending
|
||||
end
|
||||
|
||||
it 'supports multiple hostnames in request' do
|
||||
pending
|
||||
end
|
||||
end
|
8
spec/spec_helper.rb
Normal file
8
spec/spec_helper.rb
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
require 'rubygems'
|
||||
require 'bundler/setup'
|
||||
require 'rack/test'
|
||||
|
||||
require 'dyndnsd'
|
||||
require 'support/dummy_database'
|
||||
require 'support/dummy_updater'
|
29
spec/support/dummy_database.rb
Normal file
29
spec/support/dummy_database.rb
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
require 'forwardable'
|
||||
|
||||
module Dyndnsd
|
||||
class DummyDatabase
|
||||
extend Forwardable
|
||||
|
||||
def_delegators :@db, :[], :[]=, :each, :has_key?
|
||||
|
||||
def initialize(db_init)
|
||||
@db_init = db_init
|
||||
end
|
||||
|
||||
def load
|
||||
@db = @db_init
|
||||
@db_hash = @db.hash
|
||||
end
|
||||
|
||||
def save
|
||||
@db_hash = @db.hash
|
||||
end
|
||||
|
||||
def changed?
|
||||
@db_hash != @db.hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
10
spec/support/dummy_updater.rb
Normal file
10
spec/support/dummy_updater.rb
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
module Dyndnsd
|
||||
module Updater
|
||||
class Dummy
|
||||
def update(zone)
|
||||
# nothing
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user