Skip to content

Commit

Permalink
gem: allow config to contain users without any hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
cmur2 committed Sep 20, 2022
1 parent d066b3e commit 3a5b1bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 2 additions & 1 deletion lib/dyndnsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,11 @@ def handle_dyndns_request(env)
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'
Expand Down
11 changes: 11 additions & 0 deletions spec/dyndnsd/daemon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def app
'test' => {
'password' => 'secret',
'hosts' => ['foo.example.org', 'bar.example.org']
},
'test2' => {
'password' => 'ihavenohosts'
}
}
}
Expand Down Expand Up @@ -99,6 +102,14 @@ def app
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'

Expand Down

0 comments on commit 3a5b1bc

Please sign in to comment.