func init() { logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) privateKeyFilePath := flag.String("rsa-private", "./dist/key.private", "RSA private key file path") secureKeyFilePath := flag.String("secure-key", "./dist/secureKey", "password to encrypt the secure storage") usersDataPath := flag.String("data-file", "./dist/data.txt", "Login information file") flag.Parse() servicePath = cr.ServicePathPrefix + cr.Version + amPrefix resourcePath = listener + servicePath + usersPath usersList := en.New() signKey, verifyKey := app.SetupAToken(*privateKeyFilePath) loginKey := ss.GetSecureKey(*secureKeyFilePath) en.LoadInfo(*usersDataPath, loginKey, usersList) stRestful = libsecurityRestful.NewLibsecurityRestful() stRestful.SetData(usersList, loginKey, verifyKey, signKey, nil) rootCookieStr, _ := app.GenerateToken(defs.RootUserName, am.SuperUserPermission, false, clientIP, signKey) cr.TestSetCookie(rootCookieStr) for _, name := range usersName { stRestful.UsersList.AddUser(name) } go runServer() time.Sleep(100 * time.Millisecond) }
func Test_corners(t *testing.T) { logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) s, _ := NewStorage([]byte(baseSecret), true) s.AddItem("key", "value") logger.Trace.Println("The storage is", s.GetDecryptStorageData()) if s.IsSecretMatch([]byte("a1234")) == true { t.Errorf("Test fail: wrong secret match to the storage secret") } fileName := "tmp.txt" defer os.Remove(fileName) fileName1 := "tmp1.txt" defer os.Remove(fileName1) ioutil.WriteFile(fileName, []byte("12345678111111111111111111111111111111111111111111111"), os.ModePerm) ioutil.WriteFile(fileName1, []byte("12345678111111111111111111111111111111111111111111111 "), os.ModePerm) v1 := GetSecureKey(fileName) v2 := GetSecureKey(fileName) v3 := GetSecureKey(fileName1) if string(v1) != string(v2) { t.Errorf("Test fail: the same GetSecureKey return 2 different results") } if string(v1) == string(v3) { t.Errorf("Test fail: different inputs to GetSecureKey return the same results") } _, err := NewStorage([]byte("1234"), true) if err == nil { t.Errorf("Test fail: simple secret was accepted") } }
// StoreLoadTest : common store load testing for all the different properties func StoreLoadTest(t *testing.T, userData interface{}, propertyName string) { filePath := "./tmp.txt" key := "key" secret := []byte("12345678") logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) storage, err := ss.NewStorage(secret, false) if err != nil { t.Errorf("Fatal error: can't create storage, error: %v", err) } s := Serializers[propertyName] err = s.AddToStorage(key, userData, storage) if err != nil { t.Fatal("Fatal error: can't add to storage, error:", err) } err = s.AddToStorage(key, nil, storage) if err == nil { t.Errorf("Test fail: Successfully add undefined property to storage") } err = s.AddToStorage(key, userData, nil) if err == nil { t.Errorf("Test fail: Successfully add property to nil storage") } storage.StoreInfo(filePath) storage, err = ss.LoadInfo(filePath, secret) if err != nil { t.Fatal("Fatal error: can't load from storage, error:", err) } _, err = s.ReadFromStorage(key, nil) loadStorage := storage.GetDecryptStorageData() if err == nil { t.Fatal("Fatal error: Read pass but storage is nil") } _, err = s.ReadFromStorage("", loadStorage) if err == nil { t.Fatal("Fatal error: Read pass but the key is empty") } _, err = s.ReadFromStorage(key, loadStorage) if err != nil { t.Fatal("Fatal error: can't load from storage, error:", err) } data, err := s.ReadFromStorage(key, loadStorage) if err != nil { t.Fatal("Fatal error: can't read from storage, error:", err) } if s.IsEqualProperties(userData, data) == false { t.Fatal("Fatal error: Data read from storage:", s.PrintProperties(data), "is not equal to the one that was write to storage:", userData) } if s.IsEqualProperties(userData, "") == true { t.Fatal("Fatal error: unequal properies were found equal") } logger.Trace.Println("Data:", s.PrintProperties(data)) }
// Test corners: String, logger etc func Test_corners(t *testing.T) { userAm, _ := NewUserAm(SuperUserPermission, defaultPassword, defaultSalt, true) logger.Init(ioutil.Discard, ioutil.Discard, os.Stdout, os.Stderr) logger.Trace.Println("The user info is", userAm.String()) privileges := GetUsersPrivilege() for p := range privileges { if p != UserPermission && p != SuperUserPermission && p != AdminPermission { t.Errorf("Unknown permission index '%v'", p) } } }
func init() { logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) usersList := en.New() stRestful = libsecurityRestful.NewLibsecurityRestful() stRestful.SetData(usersList, nil, nil, nil, nil) stRestful.SetToFilterFlag(false) servicePath = cr.ServicePathPrefix + cr.Version + aclPrefix resourcePath = listener + servicePath go runServer() time.Sleep(100 * time.Millisecond) }
func init() { logger.Init(ioutil.Discard, ioutil.Discard, os.Stdout, os.Stderr) defs.Serializers[defs.OcraPropertyName] = &Serializer{} for _, val := range ocraValidOutputLength { ocraValidOutputLengthMap[val] = val } ocraSuiteDataInputParseStruct = []parseData{{ocraSuiteDataInputCounterToken, checkOcraDataInputCounterValidity, handleCounter, dataInputCounterRegExp}, {ocraSuiteDataInputQuestionToken, checkOcraDataInputQuestionValidity, handleQuestion, dataInputQuestionRegExp}, {ocraSuiteDataInputPasswordToken, checkOcraDataInputPasswordValidity, handlePassword, dataInputPasswordTokenRegExp}, {ocraSuiteDataInputSessionToken, checkOcraDataInputSessionValidity, handleSession, dataInputSessionTokenRegExp}, {ocraSuiteDataInputTimeStampToken, checkOcraDataInputTimeStampValidity, handleTimeStamp, dataInputTimeStampTokenRegExp}} for _, c := range ocraSuiteDataInputParseStruct { ocraSuiteDataInputValidTokensMap[c.token[0]] = c } }
func Test_StoreLoad(t *testing.T) { filePath := "./try.txt" permissions := map[string]interface{}{"add": "", "save": "", "can use it": ""} size := 20 usersName := make([]string, size, size) for i := 0; i < size; i++ { usersName[i] = fmt.Sprintf("User%d", i) } usersList := New() GenerateUserData(usersList, usersName, secret, salt) GenerateGroupList(usersList, usersName) for p := range permissions { usersList.AddPermission(Permission(p)) } //GenerateAcl(st) // done in the acl_test logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) err := usersList.StoreInfo(filePath, []byte("1234"), true) if err == nil { t.Errorf("TEst fail: successfully store with easy password") } usersList.StoreInfo(filePath, secret, false) usersList1 := New() err = LoadInfo(filePath, secret, nil) if err == nil { t.Errorf("TEst fail: successfully load from nil storage") } err = LoadInfo("", secret, nil) if err == nil { t.Errorf("Test fail: successfully load from undefined file") } err = LoadInfo(filePath, secret, usersList1) if err != nil { fmt.Println(err) } if usersList.IsEqual(usersList1) == false { t.Errorf("Test fail, Stored users list != loaded one") fmt.Println("The stored entity list:", usersList.getEntityManagerStrWithProperties()) fmt.Println("The loaded entity list:", usersList1.getEntityManagerStrWithProperties()) } if usersList.Permissions.IsEqual(usersList1.Permissions) == false { t.Errorf("Test fail, Stored permissions != loaded one") fmt.Println("The stored permisions list:", usersList.Permissions) fmt.Println("The loaded permisions list:", usersList1.getPermissions()) } }
// This example show the following: // - Discard Trace messages // - Write Info messages to stdout // - Write Warning to stdout and log file // - Write Error to stderr and log file func Example_logger() { fileName := "log-file.txt" os.Remove(fileName) file, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { log.Fatalln("Failed to open log file", fileName, ":", err) } multiW := io.MultiWriter(file, os.Stdout) multiE := io.MultiWriter(file, os.Stderr) logger.Init(ioutil.Discard, os.Stdout, multiW, multiE) logger.Trace.Println("Example: I have something standard to say") logger.Info.Println("Example: Special Information") logger.Warning.Println("Example: There is something you need to know about") logger.Error.Println("Example: Something has failed") }
func init() { logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) servicePath = cr.ServicePathPrefix + cr.Version + sPrefix resourcePath = listener + servicePath + storagePath itemPath = listener + servicePath + storageItemPath baseHeaderInfo[secretIDParam] = secretCode usersList := en.New() stRestful = libsecurityRestful.NewLibsecurityRestful() secureStorage, _ := ss.NewStorage([]byte(secretCode), true) stRestful.SetData(usersList, nil, nil, nil, secureStorage) stRestful.SetToFilterFlag(false) go runServer() time.Sleep(100 * time.Millisecond) }
func init() { logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) servicePath = cr.ServicePathPrefix + cr.Version + ocraPrefix resourcePath = listener + servicePath + usersPath usersList := en.New() stRestful = libsecurityRestful.NewLibsecurityRestful() stRestful.SetData(usersList, nil, nil, nil, nil) stRestful.SetToFilterFlag(false) for _, name := range usersName { stRestful.UsersList.AddUser(name) } go runServer() time.Sleep(100 * time.Millisecond) }
// Test corners: String, logger etc func Test_corners(t *testing.T) { pwd := []byte("ABCD12") ilegalPwd := "AB" salt := []byte("salt123") minSecret := 4 maxSecret := 10 logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) salt1, _ := NewSalt(pwd, minSecret, maxSecret, salt) logger.Trace.Println("The salt info is", salt1) _, err := GenerateSaltedPassword(pwd, minSecret, maxSecret, salt, len(pwd)) if err != nil { t.Error("Test fail: Can't generate salted password, error:", err) } _, _, err = GeneratePasswordWithRndSalt(ilegalPwd, minSecret, maxSecret) if err == nil { t.Error("Test fail: Successfully generated password with random salt for ilegal password", ilegalPwd) } _, _, err = GeneratePasswordWithRndSalt(string(pwd), minSecret, maxSecret) if err != nil { t.Error("Test fail: Can't generate password with random salt, error:", err) } }
func init() { logger.Init(ioutil.Discard, ioutil.Discard, os.Stdout, os.Stderr) defs.Serializers[defs.AclPropertyName] = &Serializer{} en.RemoveEntityFromAcl = RemoveEntityFromAcl }
func init() { logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) }
func init() { logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard) defaultPassword = []byte(password.GenerateNewValidPassword()) }