mirror of
https://github.com/cmur2/dyndnsd.git
synced 2024-12-22 00:54:22 +01:00
gem: allow config to contain users without any hosts
This commit is contained in:
parent
d066b3ecee
commit
3a5b1bcb27
@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## 3.7.1
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
- fix [TypeError](https://github.com/cmur2/dyndnsd/issues/205) when user has no hosts configured
|
||||
|
||||
## 3.7.0 (September 16th, 2022)
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
@ -215,10 +215,11 @@ module Dyndnsd
|
||||
invalid_hostnames = hostnames.select { |h| !Helper.fqdn_valid?(h, @domain) }
|
||||
return [422, {'X-DynDNS-Response' => 'hostname_malformed'}, []] if invalid_hostnames.any?
|
||||
|
||||
# we can trust this information since user was authorized by middleware
|
||||
user = env['REMOTE_USER']
|
||||
|
||||
# check for hostnames that the user does not own
|
||||
forbidden_hostnames = hostnames - @users[user]['hosts']
|
||||
forbidden_hostnames = hostnames - @users[user].fetch('hosts', [])
|
||||
return [422, {'X-DynDNS-Response' => 'host_forbidden'}, []] if forbidden_hostnames.any?
|
||||
|
||||
if params['offline'] == 'YES'
|
||||
|
@ -15,6 +15,9 @@ describe Dyndnsd::Daemon do
|
||||
'test' => {
|
||||
'password' => 'secret',
|
||||
'hosts' => ['foo.example.org', 'bar.example.org']
|
||||
},
|
||||
'test2' => {
|
||||
'password' => 'ihavenohosts'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,6 +102,14 @@ describe Dyndnsd::Daemon do
|
||||
expect(last_response.body).to eq('notfqdn')
|
||||
end
|
||||
|
||||
it 'rejects request if user does not own any hostnames' do
|
||||
authorize 'test2', 'ihavenohosts'
|
||||
|
||||
get '/nic/update?hostname=doesnotexisthost.example.org'
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to eq('nohost')
|
||||
end
|
||||
|
||||
it 'rejects request if user does not own one hostname' do
|
||||
authorize 'test', 'secret'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user