- Updated environment configuration to unify frontend for mail and drive under a single service. - Revised README to reflect changes in frontend setup and routing for the unified application. - Introduced new API documentation endpoints for better accessibility of API specifications. - Enhanced drive and mail services with improved handling of file uploads and metadata enrichment. - Implemented new API token management features, including creation, listing, and revocation of tokens. - Added tests for new functionalities in drive and mail services to ensure reliability and correctness.
38 lines
917 B
Go
38 lines
917 B
Go
package apitokens
|
|
|
|
import "testing"
|
|
|
|
func TestHashSecretDeterministic(t *testing.T) {
|
|
a := HashSecret("ulti_test_secret")
|
|
b := HashSecret("ulti_test_secret")
|
|
if len(a) != 32 {
|
|
t.Fatalf("hash length = %d, want 32", len(a))
|
|
}
|
|
for i := range a {
|
|
if a[i] != b[i] {
|
|
t.Fatal("hash not deterministic")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestHasPermission(t *testing.T) {
|
|
auth := &AuthContext{
|
|
Permissions: []PermissionGrant{
|
|
{Resource: "mail.messages", Read: true, Write: false},
|
|
{Resource: "mail.send", Read: false, Write: true},
|
|
},
|
|
}
|
|
if !HasPermission(auth, "mail.messages", false) {
|
|
t.Fatal("expected read on mail.messages")
|
|
}
|
|
if HasPermission(auth, "mail.messages", true) {
|
|
t.Fatal("did not expect write on mail.messages")
|
|
}
|
|
if !HasPermission(auth, "mail.send", true) {
|
|
t.Fatal("expected write on mail.send")
|
|
}
|
|
if HasPermission(auth, "drive.files", false) {
|
|
t.Fatal("did not expect drive.files")
|
|
}
|
|
}
|