Skip to content

Commit c952574

Browse files
committed
Adjust proxy options so additional options can be passed in. Add tests.
Tweaks to #133
1 parent 544c53c commit c952574

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,17 @@ cjson and dkjson json adapters are supplied, but custom external adapters may al
300300
auto_ssl:set("json_adapter", "resty.auto-ssl.json_adapters.dkjson")
301301
```
302302

303-
### `proxy_addr`
303+
### `http_proxy_options`
304+
*Default:* `nil`
304305

305-
The `proxy_addr` specify address of proxy which will be used for requests to issue SSL certificates.
306+
Configure an HTTP proxy to use when making OCSP stapling requests. Accepts a table of options for [lua-resty-http's `set_proxy_options`](https://github.com/ledgetech/lua-resty-http#set_proxy_options).
306307

307308
*Example:*
308309

309310
```lua
310-
auto_ssl:set("proxy_addr", "http://localhost:3128")
311+
auto_ssl:set("http_proxy_options", {
312+
http_proxy = "http://localhost:3128",
313+
})
311314
```
312315

313316
## `ssl_certificate` Configuration

lib/resty/auto-ssl/ssl_certificate.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@ local function get_ocsp_response(fullchain_der, auto_ssl_instance)
172172
-- Make the OCSP request against the OCSP server.
173173
local httpc = http.new()
174174
httpc:set_timeout(10000)
175-
if (auto_ssl_instance:get("proxy_addr") ~= nil) then
176-
httpc:set_proxy_options({
177-
http_proxy = auto_ssl_instance:get("proxy_addr")
178-
})
175+
local http_proxy_options = auto_ssl_instance:get("http_proxy_options")
176+
if http_proxy_options then
177+
httpc:set_proxy_options(http_proxy_options)
179178
end
180179

181180
local res, req_err = httpc:request_uri(ocsp_url, {

spec/proxy_spec.lua

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
local http = require "resty.http"
2+
local server = require "spec.support.server"
3+
4+
describe("proxy", function()
5+
before_each(server.stop)
6+
after_each(server.stop)
7+
8+
it("issues and renews certificates", function()
9+
server.start({
10+
auto_ssl_pre_new = [[
11+
options["http_proxy_options"] = {
12+
http_proxy = "http://127.0.0.1:9444",
13+
http_proxy_authorization = "Basic ZGVtbzp0ZXN0",
14+
}
15+
]],
16+
auto_ssl_http_config = [[
17+
server {
18+
listen 9444;
19+
20+
location / {
21+
content_by_lua_block {
22+
ngx.log(ngx.INFO, "http proxy auth: ", ngx.var.http_proxy_authorization)
23+
}
24+
}
25+
}
26+
]],
27+
})
28+
29+
local httpc = http.new()
30+
local _, connect_err = httpc:connect("127.0.0.1", 9443)
31+
assert.equal(nil, connect_err)
32+
33+
local _, ssl_err = httpc:ssl_handshake(nil, server.ngrok_hostname, true)
34+
assert.equal(nil, ssl_err)
35+
36+
local res, request_err = httpc:request({ path = "/foo" })
37+
assert.equal(nil, request_err)
38+
assert.equal(200, res.status)
39+
40+
local body, body_err = res:read_body()
41+
assert.equal(nil, body_err)
42+
assert.equal("foo", body)
43+
44+
local error_log = server.read_error_log()
45+
assert.matches("auto-ssl: issuing new certificate for " .. server.ngrok_hostname, error_log, nil, true)
46+
assert.matches("http proxy auth: Basic ZGVtbzp0ZXN0", error_log, nil, true)
47+
assert.matches("auto-ssl: failed to set ocsp stapling for " .. server.ngrok_hostname .. " - continuing anyway - failed to get ocsp response: OCSP responder returns bad response body (http://ocsp.stg-int-x1.letsencrypt.org): ,", error_log, nil, true)
48+
assert.Not.matches("[warn]", error_log, nil, true)
49+
assert.matches("[error]", error_log, nil, true)
50+
assert.Not.matches("[alert]", error_log, nil, true)
51+
assert.Not.matches("[emerg]", error_log, nil, true)
52+
end)
53+
end)

0 commit comments

Comments
 (0)