Skip to content

Commit

Permalink
refactor(db/declarative): remove sha256 in unique_field_key (#11506)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored Sep 12, 2023
1 parent 37a17eb commit 7683778
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
5 changes: 0 additions & 5 deletions kong/db/declarative/import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ local insert = table.insert
local null = ngx.null
local get_phase = ngx.get_phase
local yield = utils.yield
local sha256 = utils.sha256_hex


local DECLARATIVE_HASH_KEY = constants.DECLARATIVE_HASH_KEY
Expand Down Expand Up @@ -135,10 +134,6 @@ local function unique_field_key(schema_name, ws_id, field, value, unique_across_
ws_id = ""
end

-- LMDB imposes a default limit of 511 for keys, but the length of our unique
-- value might be unbounded, so we'll use a checksum instead of the raw value
value = sha256(value)

return schema_name .. "|" .. ws_id .. "|" .. field .. ":" .. value
end

Expand Down
13 changes: 2 additions & 11 deletions spec/01-unit/01-db/10-declarative_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@ require("spec.helpers") -- for kong.log
local declarative = require "kong.db.declarative"
local conf_loader = require "kong.conf_loader"

local to_hex = require("resty.string").to_hex
local resty_sha256 = require "resty.sha256"

local null = ngx.null


local function sha256(s)
local sha = resty_sha256:new()
sha:update(s)
return to_hex(sha:final())
end

describe("declarative", function()
describe("parse_string", function()
it("converts lyaml.null to ngx.null", function()
Expand Down Expand Up @@ -61,12 +52,12 @@ keyauth_credentials:
it("utilizes the schema name, workspace id, field name, and checksum of the field value", function()
local key = unique_field_key("services", "123", "fieldname", "test", false)
assert.is_string(key)
assert.equals("services|123|fieldname:" .. sha256("test"), key)
assert.equals("services|123|fieldname:test", key)
end)

it("omits the workspace id when 'unique_across_ws' is 'true'", function()
local key = unique_field_key("services", "123", "fieldname", "test", true)
assert.equals("services||fieldname:" .. sha256("test"), key)
assert.equals("services||fieldname:test", key)
end)
end)

Expand Down

1 comment on commit 7683778

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

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

Bazel Build

Docker image available kong/kong:76837787c80acaf7abde38434f82a25a2011f46e
Artifacts available https://github.com/Kong/kong/actions/runs/6162734987

Please sign in to comment.