MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestHMACDigestUnsupportedAlgorithm

Function TestHMACDigestUnsupportedAlgorithm

ext/security/hmac/hmac_test.go:661–691  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

659}
660
661func TestHMACDigestUnsupportedAlgorithm(t *testing.T) {
662 env, err := cel.NewEnv(
663 hmaclib.Library(hmaclib.Algorithm(crypto.SHA256)),
664 cel.Variable("msgBytes", cel.BytesType),
665 )
666 if err != nil {
667 t.Fatalf("cel.NewEnv failed: %v", err)
668 }
669 for _, expr := range []string{
670 `hmac.digest(msgBytes, 'SHA512')`,
671 `hmac.digest('msg', 'SHA512')`,
672 } {
673 t.Run(expr, func(t *testing.T) {
674 ast, issues := env.Compile(expr)
675 if issues != nil && issues.Err() != nil {
676 t.Fatalf("Compile(%q) failed: %v", expr, issues.Err())
677 }
678 prg, err := env.Program(ast)
679 if err != nil {
680 t.Fatalf("Program(%q) failed: %v", expr, err)
681 }
682 _, _, err = prg.Eval(map[string]any{"msgBytes": []byte("msg")})
683 if err == nil {
684 t.Fatalf("Eval(%q) got nil error, wanted unsupported HMAC hash algorithm error", expr)
685 }
686 if !strings.Contains(err.Error(), "unsupported HMAC hash algorithm") {
687 t.Errorf("Eval(%q) got error %v, wanted unsupported HMAC hash algorithm error", expr, err)
688 }
689 })
690 }
691}
692
693func TestHMACEqual(t *testing.T) {
694 secretBytes := []byte("my-shared-secret-key")

Callers

nothing calls this directly

Calls 8

CompileMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
VariableFunction · 0.92
ErrMethod · 0.80
EvalMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected