diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d95bb937c..55163cb6d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ------------------------------------------------------------------------------- diff --git a/cartridge/test-helpers/cluster.lua b/cartridge/test-helpers/cluster.lua index 38bf5140f..665e35bcd 100644 --- a/cartridge/test-helpers/cluster.lua +++ b/cartridge/test-helpers/cluster.lua @@ -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') @@ -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', { @@ -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 @@ -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 diff --git a/cartridge/test-helpers/server.lua b/cartridge/test-helpers/server.lua index 3214a69eb..1efca2cd6 100644 --- a/cartridge/test-helpers/server.lua +++ b/cartridge/test-helpers/server.lua @@ -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 @@ -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() @@ -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,