|
| 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