@nocobase/test 2.1.0-beta.17 → 2.1.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,6 +80,18 @@ const _BaseClient = class _BaseClient {
80
80
  };
81
81
  __name(_BaseClient, "BaseClient");
82
82
  let BaseClient = _BaseClient;
83
+ function escapeMysqlIdentifier(name) {
84
+ return `\`${String(name).replace(/`/g, "``")}\``;
85
+ }
86
+ __name(escapeMysqlIdentifier, "escapeMysqlIdentifier");
87
+ function escapeMysqlString(value) {
88
+ return `'${String(value).replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
89
+ }
90
+ __name(escapeMysqlString, "escapeMysqlString");
91
+ function mysqlAppUser() {
92
+ return String(process.env["DB_APP_USER"] || process.env["DB_USER"] || "").trim();
93
+ }
94
+ __name(mysqlAppUser, "mysqlAppUser");
83
95
  const _PostgresClient = class _PostgresClient extends BaseClient {
84
96
  async _removeDB(name) {
85
97
  await this._client.query(`DROP DATABASE IF EXISTS ${name}`);
@@ -107,7 +119,15 @@ const _MySQLClient = class _MySQLClient extends BaseClient {
107
119
  await this._client.query(`DROP DATABASE IF EXISTS ${name}`);
108
120
  }
109
121
  async _createDB(name) {
110
- await this._client.query(`CREATE DATABASE IF NOT EXISTS ${name}`);
122
+ const database = escapeMysqlIdentifier(name);
123
+ const appUser = mysqlAppUser();
124
+ if (!appUser) {
125
+ throw new Error("DB_APP_USER or DB_USER is required for MySQL test database grants.");
126
+ }
127
+ const user = escapeMysqlString(appUser);
128
+ await this._client.query(`CREATE DATABASE IF NOT EXISTS ${database}`);
129
+ await this._client.query(`GRANT ALL PRIVILEGES ON ${database}.* TO ${user}@'%'`);
130
+ await this._client.query("FLUSH PRIVILEGES");
111
131
  }
112
132
  async _createConnection() {
113
133
  return import_promise.default.createConnection({
@@ -126,7 +146,15 @@ const _MariaDBClient = class _MariaDBClient extends BaseClient {
126
146
  await this._client.query(`DROP DATABASE IF EXISTS ${name}`);
127
147
  }
128
148
  async _createDB(name) {
129
- await this._client.query(`CREATE DATABASE IF NOT EXISTS ${name}`);
149
+ const database = escapeMysqlIdentifier(name);
150
+ const appUser = mysqlAppUser();
151
+ if (!appUser) {
152
+ throw new Error("DB_APP_USER or DB_USER is required for MariaDB test database grants.");
153
+ }
154
+ const user = escapeMysqlString(appUser);
155
+ await this._client.query(`CREATE DATABASE IF NOT EXISTS ${database}`);
156
+ await this._client.query(`GRANT ALL PRIVILEGES ON ${database}.* TO ${user}@'%'`);
157
+ await this._client.query("FLUSH PRIVILEGES");
130
158
  }
131
159
  async _createConnection() {
132
160
  return await import_mariadb.default.createConnection({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/test",
3
- "version": "2.1.0-beta.17",
3
+ "version": "2.1.0-beta.19",
4
4
  "main": "lib/index.js",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./lib/index.d.ts",
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@faker-js/faker": "8.1.0",
54
- "@nocobase/server": "2.1.0-beta.17",
55
- "@nocobase/utils": "2.1.0-beta.17",
54
+ "@nocobase/server": "2.1.0-beta.19",
55
+ "@nocobase/utils": "2.1.0-beta.19",
56
56
  "@playwright/test": "^1.45.3",
57
57
  "@testing-library/jest-dom": "^6.4.2",
58
58
  "@testing-library/react": "^14.0.0",
@@ -77,5 +77,5 @@
77
77
  "vitest-dom": "^0.1.1",
78
78
  "ws": "^8.13.0"
79
79
  },
80
- "gitHead": "227d625e47174ab7b3a90170e7c6c67bbdf36e23"
80
+ "gitHead": "d89ab08dbcb25877de69827d5bad6823c27b2cbb"
81
81
  }