Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to MongoDB 7.0.4 #141

Merged
merged 25 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
- master
- develop

env:
AUTH2_JAR_NAME: kbase-auth2-test-shadow-all-0.7.0.jar

jobs:
workspace_deluxe_tests:
runs-on: ubuntu-latest
Expand All @@ -26,11 +29,7 @@ jobs:
minio: '2019-05-23T00-29-34Z'
wired_tiger: 'false'
- go: '1.12'
mongo: 'mongodb-linux-x86_64-3.6.20'
minio: '2019-05-23T00-29-34Z'
wired_tiger: 'false'
- go: '1.12'
mongo: 'mongodb-linux-x86_64-3.6.20'
mongo: 'mongodb-linux-x86_64-ubuntu2204-7.0.4'
minio: '2019-05-23T00-29-34Z'
wired_tiger: 'true'
steps:
Expand All @@ -50,10 +49,9 @@ jobs:
# move to parent dir to install binaries etc
cd ..

# set up jars
# TODO switch to the auth shadow jar
git clone https://github.com/kbase/jars
export JARSDIR=`pwd`/jars/lib/jars/
# set up auth2 jar
wget -q https://github.com/kbase/jars/raw/master/lib/jars/kbase/auth2/$AUTH2_JAR_NAME
export AUTH2JAR=`pwd`/$AUTH2_JAR_NAME

# set up mongo
wget -q http://fastdl.mongodb.org/linux/${{matrix.mongo}}.tgz
Expand All @@ -72,7 +70,7 @@ jobs:
sed -i "s#^test.mongo.exe.*#test.mongo.exe=$MONGOD#" test.cfg
sed -i "s#^test.minio.exe.*#test.minio.exe=$MINIO#" test.cfg
sed -i "s#^test.mongo.wired_tiger.*#test.mongo.wired_tiger=${{matrix.wired_tiger}}#" test.cfg
sed -i "s#^test.jars.dir.*#test.jars.dir=$JARSDIR#" test.cfg
sed -i "s#^test.auth2jar.*#test.auth2jar=$AUTH2JAR#" test.cfg
cat test.cfg

- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion auth/kbase_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (t *TestSuite) SetupSuite() {
t.mongo = mongoctl

auth, err := kbaseauthcontroller.New(kbaseauthcontroller.Params{
JarsDir: tcfg.JarsDir,
Auth2Jar: tcfg.Auth2JarPath,
MongoHost: "localhost:" + strconv.Itoa(mongoctl.GetPort()),
MongoDatabase: "test_kb_auth_provider_authdb",
RootTempDir: tcfg.TempDir,
Expand Down
11 changes: 5 additions & 6 deletions nodestore/mongostore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (t *TestSuite) TestConstructFailAddConfigIndex() {
t.Contains(err.Error(), "E11000 duplicate key error", "incorrect error")
t.Contains(err.Error(), testDB+".config", "incorrect error")
t.Contains(err.Error(), "schema_1", "incorrect error")
t.Contains(err.Error(), "dup key: { : \"schema\" }", "incorrect error")
t.Contains(err.Error(), "dup key: { ", "incorrect error")
t.Contains(err.Error(), ": \"schema\" }", "incorrect error")
}

func (t *TestSuite) TestConstructFailTwoConfigDocs() {
Expand Down Expand Up @@ -773,7 +774,7 @@ func (t *TestSuite) TestConfigIndexes() {
"_id_": false,
"schema_1": true,
}
t.checkIndexes("config", testDB+".config", expected)
t.checkIndexes("config", expected)
}

func (t *TestSuite) TestUserIndexes() {
Expand All @@ -782,20 +783,19 @@ func (t *TestSuite) TestUserIndexes() {
"user_1": true,
"id_1": true,
}
t.checkIndexes("users", testDB+".users", expected)
t.checkIndexes("users", expected)
}

func (t *TestSuite) TestNodeIndexes() {
expected := map[string]bool{
"_id_": false,
"id_1": true,
}
t.checkIndexes("nodes", testDB+".nodes", expected)
t.checkIndexes("nodes", expected)
}

func (t *TestSuite) checkIndexes(
collection string,
expectedNamespace string,
expectedIndexes map[string]bool) {
_, err := NewMongoNodeStore(t.client.Database(testDB))
if err != nil {
Expand All @@ -815,7 +815,6 @@ func (t *TestSuite) checkIndexes(
t.Fail(err.Error())
}
m := elem.Map()
t.Equal(expectedNamespace, m["ns"], "incorrect name space")
if un, ok := m["unique"]; ok {
names[m["name"].(string)] = un.(bool)
} else {
Expand Down
2 changes: 1 addition & 1 deletion service/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (t *TestSuite) addTestRole(username string, role string) {
func (t *TestSuite) setupAuth(cfg *testhelpers.TestConfig,
) (*kbaseauthcontroller.Controller, url.URL) {
auth, err := kbaseauthcontroller.New(kbaseauthcontroller.Params{
JarsDir: cfg.JarsDir,
Auth2Jar: cfg.Auth2JarPath,
MongoHost: "localhost:" + strconv.Itoa(t.mongo.GetPort()),
MongoDatabase: "test_kb_auth_provider_authdb",
RootTempDir: cfg.TempDir,
Expand Down
5 changes: 2 additions & 3 deletions test.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ test.mongo.exe=mongod
# no.
test.mongo.wired_tiger=false

# The path to the jars dir inside the jars repo (https://github.com/kbase/jars), e.g.
# [path to jars repo]/lib/jars
test.jars.dir =
# The path to the kbase auth2 service shadow test jar
test.auth2jar=

# Where to store temporary files generated during the test.
test.temp.dir=temp_test_dir
Expand Down
76 changes: 0 additions & 76 deletions test/kbaseauthcontroller/authjars.go

This file was deleted.

63 changes: 32 additions & 31 deletions test/kbaseauthcontroller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const (
// Params are Parameters for creating a KBase Auth2 service (https://github.com/kbase/auth2)
// controller.
type Params struct {
// JarsDir is the path to the /lib/jars directory of the
JarsDir string
// Auth2Jar is the path to the kbase auth2 jar.
Auth2Jar string
// MongoHost is the mongo host.
MongoHost string
// MongoDatabase is the database to use for auth data.
Expand All @@ -48,7 +48,7 @@ type Controller struct {

// New creates a new controller.
func New(p Params) (*Controller, error) {
classPath, err := getClassPath(p.JarsDir)
authJarPath, err := checkAuthJarExists(p.Auth2Jar)
if err != nil {
return nil, err
}
Expand All @@ -58,7 +58,7 @@ func New(p Params) (*Controller, error) {
if err != nil {
return nil, err
}
err = installTemplates(p.JarsDir, templateDir)
err = installTemplates(authJarPath, templateDir)
if err != nil {
return nil, err
}
Expand All @@ -72,7 +72,7 @@ func New(p Params) (*Controller, error) {
}
strport := strconv.Itoa(port)
cmdargs := []string{
"-classpath", classPath,
"-classpath", authJarPath,
"-DAUTH2_TEST_MONGOHOST=" + p.MongoHost,
"-DAUTH2_TEST_MONGODB=" + p.MongoDatabase,
"-DAUTH2_TEST_TEMPLATE_DIR=" + templateDir,
Expand Down Expand Up @@ -119,50 +119,51 @@ func waitForStartup(port string) error {
return startupErr
}

func getClassPath(jarsDir string) (string, error) {
jarsDir, err := filepath.Abs(jarsDir)
func checkAuthJarExists(auth2Jar string) (string, error) {
jpath, err := filepath.Abs(auth2Jar)
if err != nil {
return "", err
}
cp := []string(nil)
for _, j := range jars { // global variable, yech
jpath := path.Join(jarsDir, j)
if _, err := os.Stat(jpath); os.IsNotExist(err) {
return "", fmt.Errorf("Jar %v does not exist", jpath)
}
cp = append(cp, jpath)
if _, err := os.Stat(jpath); os.IsNotExist(err) {
return "", fmt.Errorf("jar %v does not exist", jpath)
}
return strings.Join(cp, ":"), nil
return jpath, nil
}

func installTemplates(jarsDir string, templateDir string) error {
templateZip := path.Join(jarsDir, authTemplates)
arch, err := zip.OpenReader(templateZip) // global variable, yech
func installTemplates(authJarPath string, templateDir string) error {
jar, err := zip.OpenReader(authJarPath)
if err != nil {
return err
}
for _, f := range arch.File {
name := f.FileHeader.Name
if !strings.HasSuffix(name, "/") { // not a directory

for _, f := range jar.File {
name := f.Name
// not a directory
if !strings.HasSuffix(name, "/") && strings.HasPrefix(name, "kbase_auth2_templates") {
name = path.Clean(name)
if path.IsAbs(name) || strings.HasPrefix(name, "..") {
return fmt.Errorf("Zip file %v contains files outside the zip directory - "+
"this is a sign of a malicious zip file", templateZip)
if filepath.Dir(name) != "kbase_auth2_templates" {
return fmt.Errorf("jar file %v contains files outside the directory - "+
"this is a sign of a malicious jar file", authJarPath)
}
target, err := filepath.Abs(path.Join(templateDir, name))
dst, err := filepath.Abs(path.Join(templateDir, filepath.Base(name)))
if err != nil {
return err
}
os.MkdirAll(path.Dir(target), 0600)
r, err := f.Open()
os.MkdirAll(path.Dir(dst), 0600)

source, err := f.Open()
if err != nil {
return err
}
defer source.Close()

destination, err := os.Create(dst)
if err != nil {
return err
}
f, err := os.Create(target)
MrCreosote marked this conversation as resolved.
Show resolved Hide resolved
defer destination.Close()

io.Copy(f, r)
r.Close()
f.Close()
io.Copy(destination, source)
}
}
return nil
Expand Down
Loading
Loading