gem: allow config to contain users without any hosts

pull/206/head
cn 6 days ago
parent d066b3ecee
commit 3a5b1bcb27
  1. 6
      CHANGELOG.md
  2. 3
      lib/dyndnsd.rb
  3. 11
      spec/dyndnsd/daemon_spec.rb

@ -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…
Cancel
Save