Skip to content

Commit 5c392f1

Browse files
authored
Merge pull request #119 from cockroachdb/secure-version-gating
Fix up version gating for secure mode
2 parents 069e7a9 + f17668a commit 5c392f1

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

testing/main_test.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ var minRequiredVersionsByORMName = map[string]struct {
193193
},
194194
}
195195

196-
// minTenantVersion is the minimum version that supports creating SQL tenants
197-
// (i.e. the `cockroach mt start-sql command). Earlier versions cannot create
198-
// tenants.
199-
var minTenantVersion = version.MustParse("v20.2.0-alpha")
200-
201196
type testInfo struct {
202197
language, orm string
203198
tableNames testTableNames // defaults to defaultTestTableNames
@@ -247,9 +242,32 @@ func testORM(t *testing.T, info testInfo) {
247242
},
248243
}
249244

250-
if crdbVersion.AtLeast(minTenantVersion) {
251-
// This cockroach version supports creating tenants, add a test case to
252-
// run a tenant server.
245+
// This cockroach version supports creating tenants, add a test case to
246+
// run a tenant server. We need at least 20.1-18 for everything to work out
247+
// as the certificate story was reworked immediately before that version
248+
// was minted.
249+
var tenantsSupported bool
250+
if err := db.QueryRow(`
251+
SELECT
252+
(major = 20 AND minor = 1 AND unstable > 17)
253+
OR (major = 20 AND minor > 1)
254+
OR (major > 20)
255+
FROM
256+
[
257+
SELECT
258+
regexp_extract(v, e'^(\\d+)\\.')::INT8 AS major,
259+
regexp_extract(v, e'^\\d+\\.(\\d+)')::INT8
260+
AS minor,
261+
regexp_extract(v, e'^\\d+\\.\\d+-(\\d+)')::INT8
262+
AS unstable
263+
FROM
264+
[SHOW CLUSTER SETTING version] AS t (v)
265+
];
266+
`,
267+
).Scan(&tenantsSupported); err != nil {
268+
t.Fatalf("unable to read cluster version: %s", err)
269+
}
270+
if tenantsSupported {
253271
tenant := newTenant(t, ts)
254272
db, dbURL, stopDB := startServerWithApplication(t, tenant, app)
255273
defer stopDB()
@@ -259,7 +277,7 @@ func testORM(t *testing.T, info testInfo) {
259277
dbURL: dbURL,
260278
})
261279
} else {
262-
t.Logf("not running tenant test case because minimum tenant version check was not satisfied (%s is < %s)", crdbVersion, minTenantVersion)
280+
t.Logf("not running tenant test case because minimum tenant version check was not satisfied")
263281
}
264282
}
265283

@@ -351,12 +369,7 @@ func testORM(t *testing.T, info testInfo) {
351369
}
352370

353371
func TestGORM(t *testing.T) {
354-
testORM(t, testInfo{
355-
language: "go",
356-
orm: "gorm",
357-
// TODO(rafi): Test secure mode. See https://github.com/cockroachdb/examples-orms/issues/117)
358-
insecure: true,
359-
})
372+
testORM(t, testInfo{language: "go", orm: "gorm"})
360373
}
361374

362375
func TestGOPG(t *testing.T) {
@@ -396,8 +409,6 @@ func TestSQLAlchemy(t *testing.T) {
396409
testORM(t, testInfo{
397410
language: "python",
398411
orm: "sqlalchemy",
399-
// TODO(rafi): Test secure mode. See https://github.com/cockroachdb/examples-orms/issues/117)
400-
insecure: true,
401412
})
402413
}
403414

@@ -414,19 +425,9 @@ func TestDjango(t *testing.T) {
414425
}
415426

416427
func TestActiveRecord(t *testing.T) {
417-
testORM(t, testInfo{
418-
language: "ruby",
419-
orm: "activerecord",
420-
// TODO(rafi): Test secure mode. See https://github.com/cockroachdb/examples-orms/issues/117)
421-
insecure: true,
422-
})
428+
testORM(t, testInfo{language: "ruby", orm: "activerecord"})
423429
}
424430

425431
func TestActiveRecord4(t *testing.T) {
426-
testORM(t, testInfo{
427-
language: "ruby",
428-
orm: "ar4",
429-
// TODO(rafi): Test secure mode. See https://github.com/cockroachdb/examples-orms/issues/117)
430-
insecure: true,
431-
})
432+
testORM(t, testInfo{language: "ruby", orm: "ar4"})
432433
}

0 commit comments

Comments
 (0)