Skip to content

Commit

Permalink
Allow to enable auth in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson committed May 29, 2024
1 parent d233220 commit 25c473a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ and this project adheres to
Unreleased
-------------------------------------------------------------------------------

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Added
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- ``auth_enabled`` param ``test-helpers.cluster`` to enable/disable auth in tests.

-------------------------------------------------------------------------------
[2.12.0] - 2024-05-28
-------------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions cartridge/test-helpers/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local fio = require('fio')
local fun = require('fun')
local log = require('log')
local uuid = require('uuid')
local digest = require('digest')

local luatest = require('luatest')
local utils = require('cartridge.utils')
Expand Down Expand Up @@ -43,6 +44,7 @@ end
-- @string[opt] object.stateboard_entrypoint Command to run stateboard.
-- @tab[opt] object.zone_distances Vshard distances between zones.
-- @number[opt] object.swim_period SWIM protocol period in seconds.
-- @bool[opt] object.auth_enabled Enable authentication.
-- @return object
function Cluster:new(object)
checks('table', {
Expand All @@ -58,6 +60,7 @@ function Cluster:new(object)
stateboard_entrypoint = '?string',
zone_distances = '?table',
swim_period = '?number',
auth_enabled = '?boolean',
})
--- Replicaset config.
-- @table @replicaset_config
Expand Down Expand Up @@ -126,6 +129,9 @@ function Cluster:initialize()
if self.env then
server_config.env = fun.chain(self.env, server_config.env or {}):tomap()
end
if self.auth_enabled then
server_config.auth_enabled = true
end
table.insert(self.servers, self:build_server(server_config, replicaset_config, i))
end
end
Expand Down
12 changes: 12 additions & 0 deletions cartridge/test-helpers/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ local fio = require('fio')
local luatest = require('luatest')
local yaml = require('yaml')
local checks = require('checks')
local digest = require('digest')

local function bauth(username, password)
local auth_data = string.format("%s:%s", username, password)
local b64_data = digest.base64_encode(auth_data)
return {authorization = 'Basic ' .. b64_data}
end

--- Build server object.
-- @function new
Expand Down Expand Up @@ -53,6 +60,8 @@ Server.constructor_checks = fun.chain(Server.constructor_checks, {
ssl_client_cert_file = '?string',
ssl_client_key_file = '?string',
ssl_client_password = '?string',

auth_enabled = '?boolean',
}):tomap()

function Server:initialize()
Expand Down Expand Up @@ -229,6 +238,9 @@ function Server:graphql(request, http_options)
end

http_options = table.copy(http_options) or {}
if self.auth_enabled then
http_options.http = { headers = bauth('admin', self.cluster_cookie) }
end
http_options.json = {
query = request.query,
variables = request.variables,
Expand Down

0 comments on commit 25c473a

Please sign in to comment.