Skip to content

Commit

Permalink
Merge pull request #3073 from hchenxa/hchenxa_fix3071
Browse files Browse the repository at this point in the history
do not hardcode the path
  • Loading branch information
k8s-ci-robot authored Sep 17, 2018
2 parents 0b2ca41 + 3dc21ea commit 8d8cdb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rootfs/etc/nginx/lua/balancer/sticky.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ local function set_cookie(self, value)
ok, err = cookie:set({
key = self.cookie_name,
value = value,
path = "/",
path = ngx.var.location_path,
domain = ngx.var.host,
httponly = true,
})
Expand Down
16 changes: 8 additions & 8 deletions rootfs/etc/nginx/lua/test/balancer/sticky_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ end

describe("Sticky", function()
before_each(function()
mock_ngx({ var = {} })
mock_ngx({ var = { location_path = "/" } })
end)

after_each(function()
reset_ngx()
end)

local test_backend = get_test_backend()
local test_backend_endpoint= test_backend.endpoints[1].address .. ":" .. test_backend.endpoints[1].port

Expand All @@ -68,7 +68,7 @@ describe("Sticky", function()
assert.equal(sticky_balancer_instance.cookie_name, default_cookie_name)
end)
end)

context("when backend specifies hash function", function()
it("returns an instance with the corresponding hash implementation", function()
local sticky_balancer_instance = sticky:new(test_backend)
Expand Down Expand Up @@ -109,18 +109,18 @@ describe("Sticky", function()
assert.equal(peer, test_backend_endpoint)
end)

it("sets a cookie on the client", function()
it("sets a cookie on the client", function()
local s = {}
cookie.new = function(self)
local test_backend_hash_fn = test_backend.sessionAffinityConfig.cookieSessionAffinity.hash
local cookie_instance = {
set = function(self, payload)
assert.equal(payload.key, test_backend.sessionAffinityConfig.cookieSessionAffinity.name)
assert.equal(payload.value, util[test_backend_hash_fn .. "_digest"](test_backend_endpoint))
assert.equal(payload.path, "/")
assert.equal(payload.path, ngx.var.location_path)
assert.equal(payload.domain, nil)
assert.equal(payload.httponly, true)
return true, nil
return true, nil
end,
get = function(k) return false end,
}
Expand All @@ -136,7 +136,7 @@ describe("Sticky", function()
context("when client has a cookie set", function()
it("does not set a cookie", function()
local s = {}
cookie.new = function(self)
cookie.new = function(self)
local return_obj = {
set = function(v) return false, nil end,
get = function(k) return test_backend_endpoint end,
Expand All @@ -156,4 +156,4 @@ describe("Sticky", function()
end)
end)
end)
end)
end)

0 comments on commit 8d8cdb0

Please sign in to comment.