Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid nameserver duplication #636

Merged
merged 4 commits into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Error loading policy chain configuration JSON with null value [PR #626](https://github.com/3scale/apicast/pull/626)
- Splitted `resolv.conf` in lines,to avoid commented lines [PR #618](https://github.com/3scale/apicast/pull/618)
- Avoid `nameserver` repetion from `RESOLVER` variable and `resolv.conf` file [PR #636](https://github.com/3scale/apicast/pull/636)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo


## Added

Expand Down
3 changes: 2 additions & 1 deletion gateway/src/resty/resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ function _M.parse_nameservers(path)

local server = match(line, '^nameserver%s+([^%s]+)')
-- TODO: implement port matching based on https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549190
if server and server ~= resolver then
-- meanwhile assuming default port 53.
if server and format("%s:%s", server, default_resolver_port) ~= tostring(resolver) then
insert(nameservers, nameserver.new(server))
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/resty/resolver_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ nameserver 127.0.0.1
end)

it('returns nameserver touples', function()
Copy link
Contributor

@mikz mikz Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this deserves a new test. Because it basically changes it so we don't have a test for the order of returned nameservers from a normal file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Also, I think that we have similar problems with other tests. For example, this test is checking that commented lines are ignored, but there isn't an it clause explaining that or an explicit assertion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in e2755eb

resty_env.set('RESOLVER', '127.0.0.1')
local nameservers = resty_resolver.parse_nameservers(tmpname)

assert.equal(2, #nameservers)
assert.same({ '127.0.0.2', 53 }, nameservers[1])
assert.same({ '127.0.0.1', 53 }, nameservers[2])
assert.same({ '127.0.0.1', 53 }, nameservers[1])
assert.same({ '127.0.0.2', 53 }, nameservers[2])
end)

it('returns search domains', function()
Expand Down
26 changes: 26 additions & 0 deletions t/resolver.t
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,29 @@ GET /t
nameservers: 1 [dead::beef]:5353
--- user_files
>>> resolv.conf


=== TEST 4: do not duplicate nameserver from RESOLVER
nameservers should not repeat if already configured
--- main_config
env RESOLVER='127.0.1.1:53';
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
init_worker_by_lua_block {
require('resty.resolver').init('$TEST_NGINX_RESOLV_CONF')
}
--- config
location = /t {
content_by_lua_block {
local nameservers = require('resty.resolver').nameservers()
ngx.say('nameservers: ', #nameservers, ' ', nameservers[1], ' ', nameservers[2])
}
}
--- request
GET /t
--- response_body
nameservers: 2 127.0.1.153 1.2.3.453
--- user_files
>>> resolv.conf
nameserver 127.0.1.1
nameserver 1.2.3.4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline at the end of the file. Would be good to set-up your editor to always keep a new-line at the EOF.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 3afea98