generated from coulomb/repo-seed
56 lines
2.0 KiB
Go
56 lines
2.0 KiB
Go
package markitect_test
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/netkingdom/flex-auth/internal/markitect"
|
|
"github.com/netkingdom/flex-auth/pkg/api"
|
|
)
|
|
|
|
func TestActionVocabularySeparatesReadFromExport(t *testing.T) {
|
|
read, ok := markitect.LookupAction(markitect.ActionRead)
|
|
if !ok {
|
|
t.Fatal("read action not found")
|
|
}
|
|
if slices.Contains(read.Capabilities, api.CapabilityExport) {
|
|
t.Fatalf("read capabilities = %v; must not include Export", read.Capabilities)
|
|
}
|
|
if !slices.Contains(read.ExposureModes, api.ExposureModeMetadata) ||
|
|
!slices.Contains(read.ExposureModes, api.ExposureModeMasked) ||
|
|
!slices.Contains(read.ExposureModes, api.ExposureModePlaintext) {
|
|
t.Fatalf("read exposure modes = %v; want metadata, masked, and plaintext", read.ExposureModes)
|
|
}
|
|
|
|
export, ok := markitect.LookupAction(markitect.ActionExport)
|
|
if !ok {
|
|
t.Fatal("export action not found")
|
|
}
|
|
if !slices.Contains(export.Capabilities, api.CapabilityExport) {
|
|
t.Fatalf("export capabilities = %v; want Export", export.Capabilities)
|
|
}
|
|
if !slices.Contains(export.ExposureModes, api.ExposureModeExportable) {
|
|
t.Fatalf("export exposure modes = %v; want Exportable", export.ExposureModes)
|
|
}
|
|
if !slices.Contains(export.RequiredContext, api.ConditionMFARequired) {
|
|
t.Fatalf("export required context = %v; want MFARequired", export.RequiredContext)
|
|
}
|
|
}
|
|
|
|
func TestActionDefinitionsMirrorVocabulary(t *testing.T) {
|
|
definitions := markitect.ActionDefinitions()
|
|
if len(definitions) != len(markitect.ActionVocabulary) {
|
|
t.Fatalf("definitions len = %d; want %d", len(definitions), len(markitect.ActionVocabulary))
|
|
}
|
|
|
|
for i, mapping := range markitect.ActionVocabulary {
|
|
definition := definitions[i]
|
|
if definition.Name != mapping.Action {
|
|
t.Fatalf("definitions[%d].Name = %q; want %q", i, definition.Name, mapping.Action)
|
|
}
|
|
if !slices.Equal(definition.Capabilities, mapping.Capabilities) {
|
|
t.Fatalf("%s capabilities = %v; want %v", mapping.Action, definition.Capabilities, mapping.Capabilities)
|
|
}
|
|
}
|
|
}
|