You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.9 KiB
112 lines
2.9 KiB
// ------------------------------------------------------------------------
|
|
// 🚀 Project Active8
|
|
// 🔗 UserStateActive Thing (activething.com) git.activething.com/go
|
|
//
|
|
// File name user_test.go
|
|
// ✍️ Created by DEV
|
|
// 📅 Modified 04/12/2024
|
|
//
|
|
// 🔒 Copyright 2024 activething.com
|
|
//
|
|
// 📜 LICENSE --------------------------------------------------------------
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
// ------------------------------------------------------------------------
|
|
|
|
package tests
|
|
|
|
import (
|
|
"brbac"
|
|
"testing"
|
|
)
|
|
|
|
func TestUserID(t *testing.T) {
|
|
// Test creating a new User
|
|
source := byte(42)
|
|
state := byte(7)
|
|
id := uint64(0x123456789ABC)
|
|
|
|
uid := brbac.NewUserID(source, state, id)
|
|
|
|
// Verify source
|
|
if got := uid.Source(); got != source {
|
|
t.Errorf("Group: expected %d, got %d", source, got)
|
|
}
|
|
|
|
// Verify state
|
|
if got := uid.State(); got != state {
|
|
t.Errorf("State: expected %d, got %d", state, got)
|
|
}
|
|
|
|
// Verify ID
|
|
if got := uid.ID(); got != id {
|
|
t.Errorf("ID: expected 0x%X, got 0x%X", id, got)
|
|
}
|
|
}
|
|
|
|
func TestUserIDSetters(t *testing.T) {
|
|
var uid brbac.User
|
|
|
|
// Test SetGroup
|
|
source := byte(55)
|
|
uid = uid.SetGroup(source)
|
|
if got := uid.Group(); got != source {
|
|
t.Errorf("SetGroup: expected %d, got %d", source, got)
|
|
}
|
|
|
|
// Test SetState
|
|
state := byte(22)
|
|
uid = uid.SetState(state)
|
|
if got := uid.State(); got != state {
|
|
t.Errorf("SetState: expected %d, got %d", state, got)
|
|
}
|
|
|
|
// Test SetID
|
|
id := uint64(0xFFFFFFFFFFFF)
|
|
uid = uid.SetID(id)
|
|
if got := uid.ID(); got != id {
|
|
t.Errorf("SetID: expected 0x%X, got 0x%X", id, got)
|
|
}
|
|
}
|
|
|
|
func TestUserIDChaining(t *testing.T) {
|
|
source := byte(33)
|
|
state := byte(11)
|
|
id := uint64(0x123456789ABC)
|
|
|
|
uid := brbac.NewUserID(source, state, id)
|
|
|
|
// Verify all components after chained creation
|
|
if got := uid.Source(); got != source {
|
|
t.Errorf("Chained Group: expected %d, got %d", source, got)
|
|
}
|
|
|
|
if got := uid.State(); got != state {
|
|
t.Errorf("Chained State: expected %d, got %d", state, got)
|
|
}
|
|
|
|
if got := uid.ID(); got != id {
|
|
t.Errorf("Chained ID: expected 0x%X, got 0x%X", id, got)
|
|
}
|
|
}
|
|
|
|
func TestUserIDOverflow(t *testing.T) {
|
|
// Test that ID is truncated to 48 bits
|
|
fullID := uint64(0xFFFFFFFFFFFFFFFF)
|
|
uid := brbac.User(0).SetID(fullID)
|
|
|
|
expectedID := fullID & brbac.userIdMask
|
|
if got := uid.ID(); got != expectedID {
|
|
t.Errorf("ID Overflow: expected 0x%X, got 0x%X", expectedID, got)
|
|
}
|
|
}
|