fix test files
This commit is contained in:
@@ -2,11 +2,19 @@ package helper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
os.Setenv("GO_ENV", "development")
|
||||||
|
code := m.Run()
|
||||||
|
os.Unsetenv("GO_ENV")
|
||||||
|
os.Exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewCircuitBreaker(t *testing.T) {
|
func TestNewCircuitBreaker(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
+8
-4
@@ -42,12 +42,16 @@ func getRSAPublicKey() (*rsa.PublicKey, error) {
|
|||||||
rsaPublicKeyOnce.Do(func() {
|
rsaPublicKeyOnce.Do(func() {
|
||||||
log.Print("Loading RSA public key from PEM certificate file")
|
log.Print("Loading RSA public key from PEM certificate file")
|
||||||
|
|
||||||
// Read PEM file
|
// Read PEM file - use path relative to executable or try both common paths
|
||||||
pemData, err := os.ReadFile("rsa/ServerCertificate.pem")
|
pemData, err := os.ReadFile("rsa/ServerCertificate.pem")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rsaPublicKeyError = fmt.Errorf("failed to read PEM file: %w", err)
|
// Try alternate path when running tests from subdirectory
|
||||||
log.Printf("Error reading PEM file: %v", rsaPublicKeyError)
|
pemData, err = os.ReadFile("../rsa/ServerCertificate.pem")
|
||||||
return
|
if err != nil {
|
||||||
|
rsaPublicKeyError = fmt.Errorf("failed to read PEM file: %w", err)
|
||||||
|
log.Printf("Error reading PEM file: %v", rsaPublicKeyError)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.Print("PEM file successfully read")
|
log.Print("PEM file successfully read")
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ import (
|
|||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
os.Setenv("GO_ENV", "development")
|
||||||
|
code := m.Run()
|
||||||
|
os.Unsetenv("GO_ENV")
|
||||||
|
os.Exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
// Test helper to generate RSA key pair and certificate
|
// Test helper to generate RSA key pair and certificate
|
||||||
func generateTestRSACertificate(t *testing.T) (privateKey *rsa.PrivateKey, certPEM []byte) {
|
func generateTestRSACertificate(t *testing.T) (privateKey *rsa.PrivateKey, certPEM []byte) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|||||||
@@ -100,8 +100,8 @@ func GetUserAttributes(userID string) (map[string]string, error) {
|
|||||||
func GetUserByID(userID string) (*models.User, error) {
|
func GetUserByID(userID string) (*models.User, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT user_id, first_name, middle_initial, last_name, suffix, email_address,
|
SELECT user_id, first_name, middle_initial, last_name, suffix, email_address,
|
||||||
emp_id, is_logged_in,
|
emp_id, is_logged_in, first_logged_in, home_address, contact_number, device_id,
|
||||||
first_logged_in, home_address, contact_number, device_id, role_id, is_deleted, secret_key, is_activated, created_at, updated_at
|
role_id, is_deleted, secret_key, is_activated, created_at, updated_at
|
||||||
FROM uess_user_management.users
|
FROM uess_user_management.users
|
||||||
WHERE user_id = ? AND is_deleted = 'N'
|
WHERE user_id = ? AND is_deleted = 'N'
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
|||||||
@@ -109,13 +109,12 @@ func TestGetUserByIDSuccess(t *testing.T) {
|
|||||||
|
|
||||||
rows := sqlmock.NewRows([]string{
|
rows := sqlmock.NewRows([]string{
|
||||||
"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at",
|
||||||
}).AddRow(
|
}).AddRow(
|
||||||
"user123", "John", "M", "Doe", "Jr", "john@example.com",
|
"user123", "John", "M", "Doe", "Jr", "john@example.com",
|
||||||
"regular", "EMP001", "01", "02", "03", "04", "05", "Y",
|
"EMP001", "Y", "Y", "123 Main St", "1234567890", "device001",
|
||||||
"2023-01-01", "123 Main St", "1234567890", "device001", 1,
|
1, "N", "secret", "Y", testTime, testTime,
|
||||||
2, "N", "secret", "Y", testTime, testTime,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name").
|
mock.ExpectQuery("SELECT user_id, first_name").
|
||||||
@@ -316,9 +315,8 @@ func TestGetUserByIDEmptyID(t *testing.T) {
|
|||||||
|
|
||||||
rows := sqlmock.NewRows([]string{
|
rows := sqlmock.NewRows([]string{
|
||||||
"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at",
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Match the actual query format with all the fields
|
// Match the actual query format with all the fields
|
||||||
|
|||||||
@@ -6,12 +6,20 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/DATA-DOG/go-sqlmock"
|
"github.com/DATA-DOG/go-sqlmock"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
os.Setenv("GO_ENV", "development")
|
||||||
|
code := m.Run()
|
||||||
|
os.Unsetenv("GO_ENV")
|
||||||
|
os.Exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
func setupMockDB(t *testing.T) (*sql.DB, sqlmock.Sqlmock, func()) {
|
func setupMockDB(t *testing.T) (*sql.DB, sqlmock.Sqlmock, func()) {
|
||||||
mockDB, mock, err := sqlmock.New()
|
mockDB, mock, err := sqlmock.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -99,7 +107,7 @@ func TestSetupRoutes_AuthCheckEndpoint(t *testing.T) {
|
|||||||
if w.Code == http.StatusNotFound {
|
if w.Code == http.StatusNotFound {
|
||||||
t.Error("Auth check endpoint should be registered")
|
t.Error("Auth check endpoint should be registered")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will likely return 401 (no JWT) or 500 (no DB) but that's OK - route exists
|
// Will likely return 401 (no JWT) or 500 (no DB) but that's OK - route exists
|
||||||
if w.Code != http.StatusUnauthorized && w.Code != http.StatusInternalServerError && w.Code != http.StatusForbidden {
|
if w.Code != http.StatusUnauthorized && w.Code != http.StatusInternalServerError && w.Code != http.StatusForbidden {
|
||||||
t.Logf("Auth check returned status %d (expected 401, 403, or 500 without proper setup)", w.Code)
|
t.Logf("Auth check returned status %d (expected 401, 403, or 500 without proper setup)", w.Code)
|
||||||
|
|||||||
+28
-42
@@ -41,13 +41,11 @@ func TestAuthorize_PermissionNotFound(t *testing.T) {
|
|||||||
|
|
||||||
// Mock user query
|
// Mock user query
|
||||||
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
|
||||||
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
||||||
"regular", "EMP123", "01", "001", "001", "01", "001", "Y",
|
"EMP123", "Y", "Y", "123 Street", "09123456789", "device1",
|
||||||
"Y", "123 Street", "09123456789", "device1", 1,
|
1, "N", "secret", "Y", time.Now(), time.Now())
|
||||||
"N", "secret", "Y", time.Now(), time.Now())
|
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
||||||
WithArgs("user123").
|
WithArgs("user123").
|
||||||
@@ -85,13 +83,11 @@ func TestAuthorize_Success(t *testing.T) {
|
|||||||
|
|
||||||
// Mock user query
|
// Mock user query
|
||||||
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
|
||||||
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
||||||
"regular", "EMP123", "01", "001", "001", "01", "001", "Y",
|
"EMP123", "Y", "Y", "123 Street", "09123456789", "device1",
|
||||||
"Y", "123 Street", "09123456789", "device1", 1,
|
1, "N", "secret", "Y", time.Now(), time.Now())
|
||||||
"N", "secret", "Y", time.Now(), time.Now())
|
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
||||||
WithArgs("user123").
|
WithArgs("user123").
|
||||||
@@ -147,13 +143,11 @@ func TestAuthorize_UserAttributesError(t *testing.T) {
|
|||||||
|
|
||||||
// Mock user query
|
// Mock user query
|
||||||
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
|
||||||
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
||||||
"regular", "EMP123", "01", "001", "001", "01", "001", "Y",
|
"EMP123", "Y", "Y", "123 Street", "09123456789", "device1",
|
||||||
"Y", "123 Street", "09123456789", "device1", 1,
|
1, "N", "secret", "Y", time.Now(), time.Now())
|
||||||
"N", "secret", "Y", time.Now(), time.Now())
|
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
||||||
WithArgs("user123").
|
WithArgs("user123").
|
||||||
@@ -196,13 +190,11 @@ func TestAuthorize_PolicyAttributesError(t *testing.T) {
|
|||||||
|
|
||||||
// Mock user query
|
// Mock user query
|
||||||
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
|
||||||
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
||||||
"regular", "EMP123", "01", "001", "001", "01", "001", "Y",
|
"EMP123", "Y", "Y", "123 Street", "09123456789", "device1",
|
||||||
"Y", "123 Street", "09123456789", "device1", 1,
|
1, "N", "secret", "Y", time.Now(), time.Now())
|
||||||
"N", "secret", "Y", time.Now(), time.Now())
|
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
||||||
WithArgs("user123").
|
WithArgs("user123").
|
||||||
@@ -245,13 +237,11 @@ func TestCheckPermission_Success(t *testing.T) {
|
|||||||
|
|
||||||
// Mock user query
|
// Mock user query
|
||||||
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
|
||||||
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
||||||
"regular", "EMP123", "01", "001", "001", "01", "001", "Y",
|
"EMP123", "Y", "Y", "123 Street", "09123456789", "device1",
|
||||||
"Y", "123 Street", "09123456789", "device1", 1,
|
1, "N", "secret", "Y", time.Now(), time.Now())
|
||||||
"N", "secret", "Y", time.Now(), time.Now())
|
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
||||||
WithArgs("user123").
|
WithArgs("user123").
|
||||||
@@ -300,13 +290,11 @@ func TestCheckPermission_Denied(t *testing.T) {
|
|||||||
|
|
||||||
// Mock user query
|
// Mock user query
|
||||||
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
|
||||||
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
||||||
"regular", "EMP123", "01", "001", "001", "01", "001", "Y",
|
"EMP123", "Y", "Y", "123 Street", "09123456789", "device1",
|
||||||
"Y", "123 Street", "09123456789", "device1", 1,
|
1, "N", "secret", "Y", time.Now(), time.Now())
|
||||||
"N", "secret", "Y", time.Now(), time.Now())
|
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
||||||
WithArgs("user123").
|
WithArgs("user123").
|
||||||
@@ -337,13 +325,11 @@ func TestCheckPermission_NilResourceData(t *testing.T) {
|
|||||||
|
|
||||||
// Mock user query
|
// Mock user query
|
||||||
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
|
||||||
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
||||||
"regular", "EMP123", "01", "001", "001", "01", "001", "Y",
|
"EMP123", "Y", "Y", "123 Street", "09123456789", "device1",
|
||||||
"Y", "123 Street", "09123456789", "device1", 1,
|
1, "N", "secret", "Y", time.Now(), time.Now())
|
||||||
"N", "secret", "Y", time.Now(), time.Now())
|
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
||||||
WithArgs("user123").
|
WithArgs("user123").
|
||||||
|
|||||||
@@ -220,13 +220,11 @@ func TestAuthorizeWithCache_Success(t *testing.T) {
|
|||||||
|
|
||||||
// Mock user query (needed to get role_id)
|
// Mock user query (needed to get role_id)
|
||||||
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
|
||||||
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
||||||
"regular", "EMP123", "01", "001", "001", "01", "001", "Y",
|
"EMP123", "Y", "Y", "123 Street", "09123456789", "device1",
|
||||||
"Y", "123 Street", "09123456789", "device1", 1,
|
1, "N", "secret", "Y", time.Now(), time.Now())
|
||||||
"N", "secret", "Y", time.Now(), time.Now())
|
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
||||||
WithArgs("user123").
|
WithArgs("user123").
|
||||||
@@ -277,13 +275,11 @@ func TestAuthorizeWithCache_PermissionNotFound(t *testing.T) {
|
|||||||
|
|
||||||
// Mock user query
|
// Mock user query
|
||||||
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
userRows := sqlmock.NewRows([]string{"user_id", "first_name", "middle_initial", "last_name", "suffix", "email_address",
|
||||||
"account_type", "emp_id", "reg", "prov", "aProv", "mun", "bgy", "is_logged_in",
|
"emp_id", "is_logged_in", "first_logged_in", "home_address", "contact_number", "device_id",
|
||||||
"first_logged_in", "address", "contact_number", "device_id", "role_id",
|
"role_id", "is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
||||||
"is_deleted", "secret_key", "is_activated", "created_at", "updated_at"}).
|
|
||||||
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
AddRow("user123", "John", "", "Doe", "", "john@example.com",
|
||||||
"regular", "EMP123", "01", "001", "001", "01", "001", "Y",
|
"EMP123", "Y", "Y", "123 Street", "09123456789", "device1",
|
||||||
"Y", "123 Street", "09123456789", "device1", 1,
|
1, "N", "secret", "Y", time.Now(), time.Now())
|
||||||
"N", "secret", "Y", time.Now(), time.Now())
|
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
mock.ExpectQuery("SELECT user_id, first_name, middle_initial, last_name, suffix, email_address").
|
||||||
WithArgs("user123").
|
WithArgs("user123").
|
||||||
|
|||||||
@@ -122,6 +122,10 @@ func inComparison(actual, expected string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func evaluatePolicy(policyAttribute models.PolicyAttribute, ctx *models.AuthorizationContext) (bool, string) {
|
func evaluatePolicy(policyAttribute models.PolicyAttribute, ctx *models.AuthorizationContext) (bool, string) {
|
||||||
|
if ctx == nil {
|
||||||
|
return false, "Authorization context is nil"
|
||||||
|
}
|
||||||
|
|
||||||
var actualValue string
|
var actualValue string
|
||||||
var exists bool
|
var exists bool
|
||||||
|
|
||||||
|
|||||||
@@ -919,12 +919,12 @@ func TestEvaluatePolicies_RegionBypassForAdminRoles(t *testing.T) {
|
|||||||
description: "Super Admin role string should bypass region check",
|
description: "Super Admin role string should bypass region check",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Admin role bypasses region check",
|
name: "Admin role does not bypass region check",
|
||||||
roleID: "Admin",
|
roleID: "Admin",
|
||||||
userRegion: "03",
|
userRegion: "03",
|
||||||
resourceRegion: "01",
|
resourceRegion: "01",
|
||||||
shouldBeAllowed: true,
|
shouldBeAllowed: false,
|
||||||
description: "Admin role string should bypass region check",
|
description: "Admin role string should not bypass region check",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user