3c7b8278ce
- usePermissions ORs current user roles + @everyone only (not all server roles) - cache myRolesByServer; load on active server; refresh after self role edit - gate/notify @everyone and @channel; plain @username push; special mention UI - refresh FEATURE_PARITY (DMs exist; drop stale critical gaps) - README production deploy notes dumpster.service - unit tests for permission bits and broadcast mention tokens
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package permissions
|
|
|
|
import "testing"
|
|
|
|
func TestHas(t *testing.T) {
|
|
set := VIEW_CHANNEL | SEND_MESSAGES | MENTION_EVERYONE
|
|
|
|
if !Has(set, VIEW_CHANNEL) {
|
|
t.Fatal("expected VIEW_CHANNEL")
|
|
}
|
|
if !Has(set, SEND_MESSAGES) {
|
|
t.Fatal("expected SEND_MESSAGES")
|
|
}
|
|
if Has(set, KICK_MEMBERS) {
|
|
t.Fatal("did not expect KICK_MEMBERS")
|
|
}
|
|
if !Has(set, VIEW_CHANNEL|SEND_MESSAGES) {
|
|
t.Fatal("expected multi-bit all-present")
|
|
}
|
|
if Has(set, VIEW_CHANNEL|KICK_MEMBERS) {
|
|
t.Fatal("multi-bit should require all bits")
|
|
}
|
|
}
|
|
|
|
func TestAdministratorBypassSemantics(t *testing.T) {
|
|
// Client/backend convention: ADMINISTRATOR implies all gates when checked separately.
|
|
if !Has(ADMINISTRATOR, ADMINISTRATOR) {
|
|
t.Fatal("admin flag self")
|
|
}
|
|
// ADMINISTRATOR alone does not set other bits; Has is pure bit check.
|
|
if Has(ADMINISTRATOR, KICK_MEMBERS) {
|
|
t.Fatal("Has is not an admin-implies-all helper; CheckPermission does that")
|
|
}
|
|
}
|
|
|
|
func TestDefaultEveryoneDoesNotIncludeMentionEveryone(t *testing.T) {
|
|
if Has(DefaultEveryonePermissions, MENTION_EVERYONE) {
|
|
t.Fatal("@everyone default must not grant MENTION_EVERYONE")
|
|
}
|
|
if !Has(DefaultEveryonePermissions, SEND_MESSAGES) {
|
|
t.Fatal("@everyone default should grant SEND_MESSAGES")
|
|
}
|
|
}
|
|
|
|
func TestAddRemove(t *testing.T) {
|
|
p := int64(0)
|
|
p = Add(p, VIEW_CHANNEL)
|
|
p = Add(p, KICK_MEMBERS)
|
|
if !Has(p, VIEW_CHANNEL|KICK_MEMBERS) {
|
|
t.Fatal("Add failed")
|
|
}
|
|
p = Remove(p, KICK_MEMBERS)
|
|
if Has(p, KICK_MEMBERS) {
|
|
t.Fatal("Remove failed")
|
|
}
|
|
if !Has(p, VIEW_CHANNEL) {
|
|
t.Fatal("Remove cleared wrong bit")
|
|
}
|
|
}
|