Skip to content

Commit

Permalink
GODRIVER-1530 GODRIVER-1213 Fix the enterprise auth test runner. (#1118)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Rewis <32186188+benjirewis@users.noreply.github.com>
  • Loading branch information
matthewdale and benjirewis committed Nov 2, 2022
1 parent 7586dd7 commit 1123dac
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 271 deletions.
14 changes: 10 additions & 4 deletions .evergreen/config.yml
Expand Up @@ -335,7 +335,6 @@ functions:
- command: shell.exec
type: test
params:
silent: true
working_dir: src/go.mongodb.org/mongo-driver
script: |
# DO NOT ECHO WITH XTRACE
Expand All @@ -350,7 +349,10 @@ functions:
export GOROOT="${GO_DIST}"
export GOCACHE="$GOCACHE"
export PATH="${GCC_PATH}:${GO_DIST}/bin:$PATH"
MONGODB_URI="${MONGODB_URI}" MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}" make -s evg-test-auth
export MONGODB_URI="${MONGODB_URI}"
export MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}"
make -s evg-test-enterprise-auth
run-enterprise-gssapi-auth-tests:
- command: shell.exec
Expand All @@ -377,7 +379,9 @@ functions:
export GOROOT="${GO_DIST}"
export GOCACHE="$GOCACHE"
export PATH="${GCC_PATH}:${GO_DIST}/bin:$PATH"
MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}" make -s evg-test-auth
export MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}"
make -s evg-test-enterprise-auth
run-enterprise-gssapi-service-host-auth-tests:
- command: shell.exec
Expand All @@ -404,7 +408,9 @@ functions:
export GOROOT="${GO_DIST}"
export GOCACHE="$GOCACHE"
export PATH="${GCC_PATH}:${GO_DIST}/bin:$PATH"
MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}" make -s evg-test-auth
export MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}"
make -s evg-test-enterprise-auth
run-atlas-test:
- command: shell.exec
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -29,7 +29,7 @@ build:

.PHONY: build-examples
build-examples:
go build $(BUILD_TAGS) ./examples/... ./x/mongo/driver/examples/...
go build $(BUILD_TAGS) ./examples/...

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

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

.PHONY: evg-test-kmip
evg-test-kmip:
Expand Down
51 changes: 51 additions & 0 deletions cmd/testentauth/main.go
@@ -0,0 +1,51 @@
// Copyright (C) MongoDB, Inc. 2022-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

package main

import (
"context"
"log"
"os"
"time"

"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
)

func main() {
uri := os.Getenv("MONGODB_URI")
compressor := os.Getenv("MONGO_GO_DRIVER_COMPRESSOR")

client, err := mongo.Connect(
context.Background(),
options.Client().ApplyURI(uri).SetCompressors([]string{compressor}))
if err != nil {
log.Fatalf("Error connecting client: %v", err)
}

// Use the defaultauthdb (i.e. the database name after the "/") specified in the connection
// string to run the count operation.
cs, err := connstring.Parse(uri)
if err != nil {
log.Fatalf("Error parsing connection string: %v", err)
}
if cs.Database == "" {
log.Fatal("Connection string must contain a defaultauthdb.")
}

coll := client.Database(cs.Database).Collection("test")

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

count, err := coll.EstimatedDocumentCount(ctx)
if err != nil {
log.Fatalf("failed executing count command: %v", err)
}
log.Println("Count of test collection:", count)
}
2 changes: 1 addition & 1 deletion x/mongo/driver/connstring/connstring.go
Expand Up @@ -494,7 +494,7 @@ func (p *parser) validateAuth() error {
return fmt.Errorf("username required for GSSAPI")
}
for k := range p.AuthMechanismProperties {
if k != "SERVICE_NAME" && k != "CANONICALIZE_HOST_NAME" && k != "SERVICE_REALM" {
if k != "SERVICE_NAME" && k != "CANONICALIZE_HOST_NAME" && k != "SERVICE_REALM" && k != "SERVICE_HOST" {
return fmt.Errorf("invalid auth property for GSSAPI")
}
}
Expand Down
59 changes: 0 additions & 59 deletions x/mongo/driver/examples/count/main.go

This file was deleted.

40 changes: 0 additions & 40 deletions x/mongo/driver/examples/server_monitoring/main.go

This file was deleted.

163 changes: 0 additions & 163 deletions x/mongo/driver/examples/workload/main.go

This file was deleted.

0 comments on commit 1123dac

Please sign in to comment.