1
0
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:
cn 2022-09-20 19:30:02 +02:00
parent d066b3ecee
commit 3a5b1bcb27
3 changed files with 19 additions and 1 deletions

View File

@ -1,5 +1,11 @@
# Changelog # 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) ## 3.7.0 (September 16th, 2022)
IMPROVEMENTS: IMPROVEMENTS:

View File

@ -215,10 +215,11 @@ module Dyndnsd
invalid_hostnames = hostnames.select { |h| !Helper.fqdn_valid?(h, @domain) } invalid_hostnames = hostnames.select { |h| !Helper.fqdn_valid?(h, @domain) }
return [422, {'X-DynDNS-Response' => 'hostname_malformed'}, []] if invalid_hostnames.any? 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'] user = env['REMOTE_USER']
# check for hostnames that the user does not own # 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? return [422, {'X-DynDNS-Response' => 'host_forbidden'}, []] if forbidden_hostnames.any?
if params['offline'] == 'YES' if params['offline'] == 'YES'

View File

@ -15,6 +15,9 @@ describe Dyndnsd::Daemon do
'test' => { 'test' => {
'password' => 'secret', 'password' => 'secret',
'hosts' => ['foo.example.org', 'bar.example.org'] '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') expect(last_response.body).to eq('notfqdn')
end 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 it 'rejects request if user does not own one hostname' do
authorize 'test', 'secret' authorize 'test', 'secret'