mirror of
https://github.com/cmur2/dyndnsd.git
synced 2025-06-26 02:30:22 +02:00
daemon: move authorization check to daemon making it testable
This commit is contained in:
@ -18,11 +18,9 @@ describe Dyndnsd::Daemon do
|
||||
}
|
||||
db = Dyndnsd::DummyDatabase.new({})
|
||||
updater = Dyndnsd::Updater::Dummy.new
|
||||
app = Dyndnsd::Daemon.new(config, db, updater)
|
||||
daemon = Dyndnsd::Daemon.new(config, db, updater)
|
||||
|
||||
app = Rack::Auth::Basic.new(app, "DynDNS") do |user,pass|
|
||||
(config['users'].has_key? user) and (config['users'][user]['password'] == pass)
|
||||
end
|
||||
app = Rack::Auth::Basic.new(daemon, "DynDNS", &daemon.method(:is_authorized?))
|
||||
|
||||
app = Dyndnsd::Responder::DynDNSStyle.new(app)
|
||||
end
|
||||
@ -33,6 +31,13 @@ describe Dyndnsd::Daemon do
|
||||
expect(last_response.body).to eq('badauth')
|
||||
end
|
||||
|
||||
it 'requires configured correct credentials' do
|
||||
authorize 'test', 'wrongsecret'
|
||||
get '/'
|
||||
expect(last_response.status).to eq(401)
|
||||
expect(last_response.body).to eq('badauth')
|
||||
end
|
||||
|
||||
it 'only supports GET requests' do
|
||||
authorize 'test', 'secret'
|
||||
post '/nic/update'
|
||||
@ -94,6 +99,7 @@ describe Dyndnsd::Daemon do
|
||||
|
||||
it 'rejects request if user does not own one hostname' do
|
||||
authorize 'test', 'secret'
|
||||
|
||||
get '/nic/update?hostname=notmyhost.example.org'
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to eq('nohost')
|
||||
|
Reference in New Issue
Block a user