github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/config-utils_test.go (about) 1 // Copyright (c) 2015-2022 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import "testing" 21 22 // Tests valid host URL functionality. 23 func TestValidHostURL(t *testing.T) { 24 testCases := []struct { 25 hostURL string 26 isHost bool 27 }{ 28 { 29 hostURL: "https://localhost:9000", 30 isHost: true, 31 }, 32 { 33 hostURL: "/", 34 isHost: false, 35 }, 36 } 37 38 for _, testCase := range testCases { 39 isHost := isValidHostURL(testCase.hostURL) 40 if testCase.isHost != isHost { 41 t.Fatalf("Expected %t, got %t", testCase.isHost, isHost) 42 } 43 } 44 } 45 46 func TestIsValidAPI(t *testing.T) { 47 equalAssert(isValidAPI("s3V2"), true, t) 48 equalAssert(isValidAPI("S3v2"), true, t) 49 equalAssert(isValidAPI("s3"), false, t) 50 } 51 52 func equalAssert(ok1, ok2 bool, t *testing.T) { 53 if ok1 != ok2 { 54 t.Errorf("Expected %t, got %t", ok2, ok1) 55 } 56 } 57 58 // Tests valid and invalid secret keys. 59 func TestValidSecretKeys(t *testing.T) { 60 equalAssert(isValidSecretKey("aaa"), false, t) 61 62 equalAssert(isValidSecretKey(""), true, t) 63 equalAssert(isValidSecretKey("password"), true, t) 64 equalAssert(isValidSecretKey("password%%"), true, t) 65 equalAssert(isValidSecretKey("BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"), true, t) 66 } 67 68 // Tests valid and invalid access keys. 69 func TestValidAccessKeys(t *testing.T) { 70 equalAssert(isValidAccessKey("aa"), false, t) 71 72 equalAssert(isValidAccessKey(""), true, t) 73 equalAssert(isValidAccessKey("adm"), true, t) 74 equalAssert(isValidAccessKey("admin"), true, t) 75 equalAssert(isValidAccessKey("$$%%%%%3333"), true, t) 76 equalAssert(isValidAccessKey("c67W2-r4MAyAYScRl"), true, t) 77 equalAssert(isValidAccessKey("EXOb76bfeb1234562iu679f11588"), true, t) 78 equalAssert(isValidAccessKey("BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"), true, t) 79 }