- Introduced error handling for non-existent servers and users. - Updated user management methods to include email retrieval. - Modified user creation to accept password as a parameter. - Added server management methods for retrieving friends and backups. - Removed obsolete PostgreSQL implementation. - Enhanced SQLite implementation with new SQL scripts for user and server management. - Implemented encryption for user passwords using AES-192 and scrypt. - Added tests for database operations and encryption functionality. - Improved server and user structures to include additional fields. Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
35 lines
836 B
Go
35 lines
836 B
Go
package encrypt
|
|
|
|
import "testing"
|
|
|
|
var (
|
|
DefaultKey = "golang_test"
|
|
PasswordToEncode = "Google#@128877"
|
|
)
|
|
|
|
func TestPassword(t *testing.T) {
|
|
// Encrypt password
|
|
passEncripted, err := Encrypt(DefaultKey, PasswordToEncode)
|
|
if err != nil {
|
|
t.Errorf("Cannot encrypt password: %s", err)
|
|
return
|
|
}
|
|
t.Logf("Password encrypted: %s", passEncripted)
|
|
|
|
// Descrypt password
|
|
pass, err := Decrypt(DefaultKey, passEncripted)
|
|
if err != nil {
|
|
t.Errorf("Cannot decrypt password: %s", err)
|
|
return
|
|
} else if pass != PasswordToEncode {
|
|
t.Errorf("passwords is not same:\n\t%s\n\t%s", PasswordToEncode, pass)
|
|
return
|
|
}
|
|
|
|
// Fail descrypt
|
|
pass, err = Decrypt(DefaultKey+"google", passEncripted)
|
|
if err == nil || pass == PasswordToEncode {
|
|
t.Errorf("password required return invalided:\n\t%s\n\t%s", PasswordToEncode, pass)
|
|
}
|
|
}
|