Skip to content

Commit 1123dac

Browse files
GODRIVER-1530 GODRIVER-1213 Fix the enterprise auth test runner. (#1118)
Co-authored-by: Benjamin Rewis <[email protected]>
1 parent 7586dd7 commit 1123dac

File tree

7 files changed

+66
-271
lines changed

7 files changed

+66
-271
lines changed

.evergreen/config.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ functions:
335335
- command: shell.exec
336336
type: test
337337
params:
338-
silent: true
339338
working_dir: src/go.mongodb.org/mongo-driver
340339
script: |
341340
# DO NOT ECHO WITH XTRACE
@@ -350,7 +349,10 @@ functions:
350349
export GOROOT="${GO_DIST}"
351350
export GOCACHE="$GOCACHE"
352351
export PATH="${GCC_PATH}:${GO_DIST}/bin:$PATH"
353-
MONGODB_URI="${MONGODB_URI}" MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}" make -s evg-test-auth
352+
export MONGODB_URI="${MONGODB_URI}"
353+
export MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}"
354+
355+
make -s evg-test-enterprise-auth
354356
355357
run-enterprise-gssapi-auth-tests:
356358
- command: shell.exec
@@ -377,7 +379,9 @@ functions:
377379
export GOROOT="${GO_DIST}"
378380
export GOCACHE="$GOCACHE"
379381
export PATH="${GCC_PATH}:${GO_DIST}/bin:$PATH"
380-
MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}" make -s evg-test-auth
382+
export MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}"
383+
384+
make -s evg-test-enterprise-auth
381385
382386
run-enterprise-gssapi-service-host-auth-tests:
383387
- command: shell.exec
@@ -404,7 +408,9 @@ functions:
404408
export GOROOT="${GO_DIST}"
405409
export GOCACHE="$GOCACHE"
406410
export PATH="${GCC_PATH}:${GO_DIST}/bin:$PATH"
407-
MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}" make -s evg-test-auth
411+
export MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}"
412+
413+
make -s evg-test-enterprise-auth
408414
409415
run-atlas-test:
410416
- command: shell.exec

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ build:
2929

3030
.PHONY: build-examples
3131
build-examples:
32-
go build $(BUILD_TAGS) ./examples/... ./x/mongo/driver/examples/...
32+
go build $(BUILD_TAGS) ./examples/...
3333

3434
.PHONY: build-no-tags
3535
build-no-tags:
@@ -128,9 +128,9 @@ evg-test-atlas-data-lake:
128128
ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./mongo/integration -run TestUnifiedSpecs/atlas-data-lake-testing >> spec_test.suite
129129
ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./mongo/integration -run TestAtlasDataLake >> spec_test.suite
130130

131-
.PHONY: evg-test-auth
132-
evg-test-auth:
133-
go run -tags gssapi ./x/mongo/driver/examples/count/main.go -uri $(MONGODB_URI)
131+
.PHONY: evg-test-enterprise-auth
132+
evg-test-enterprise-auth:
133+
go run -tags gssapi ./cmd/testentauth/main.go
134134

135135
.PHONY: evg-test-kmip
136136
evg-test-kmip:

cmd/testentauth/main.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) MongoDB, Inc. 2022-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package main
8+
9+
import (
10+
"context"
11+
"log"
12+
"os"
13+
"time"
14+
15+
"go.mongodb.org/mongo-driver/mongo"
16+
"go.mongodb.org/mongo-driver/mongo/options"
17+
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
18+
)
19+
20+
func main() {
21+
uri := os.Getenv("MONGODB_URI")
22+
compressor := os.Getenv("MONGO_GO_DRIVER_COMPRESSOR")
23+
24+
client, err := mongo.Connect(
25+
context.Background(),
26+
options.Client().ApplyURI(uri).SetCompressors([]string{compressor}))
27+
if err != nil {
28+
log.Fatalf("Error connecting client: %v", err)
29+
}
30+
31+
// Use the defaultauthdb (i.e. the database name after the "/") specified in the connection
32+
// string to run the count operation.
33+
cs, err := connstring.Parse(uri)
34+
if err != nil {
35+
log.Fatalf("Error parsing connection string: %v", err)
36+
}
37+
if cs.Database == "" {
38+
log.Fatal("Connection string must contain a defaultauthdb.")
39+
}
40+
41+
coll := client.Database(cs.Database).Collection("test")
42+
43+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
44+
defer cancel()
45+
46+
count, err := coll.EstimatedDocumentCount(ctx)
47+
if err != nil {
48+
log.Fatalf("failed executing count command: %v", err)
49+
}
50+
log.Println("Count of test collection:", count)
51+
}

x/mongo/driver/connstring/connstring.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func (p *parser) validateAuth() error {
494494
return fmt.Errorf("username required for GSSAPI")
495495
}
496496
for k := range p.AuthMechanismProperties {
497-
if k != "SERVICE_NAME" && k != "CANONICALIZE_HOST_NAME" && k != "SERVICE_REALM" {
497+
if k != "SERVICE_NAME" && k != "CANONICALIZE_HOST_NAME" && k != "SERVICE_REALM" && k != "SERVICE_HOST" {
498498
return fmt.Errorf("invalid auth property for GSSAPI")
499499
}
500500
}

x/mongo/driver/examples/count/main.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

x/mongo/driver/examples/server_monitoring/main.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

x/mongo/driver/examples/workload/main.go

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)