Files
slsa-verifier/verifiers/utils/dsse_test.go
laurentsimon 82a12591ff feat: npm default runner support (#495)
* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

* update

Signed-off-by: laurentsimon <laurentsimon@google.com>

---------

Signed-off-by: laurentsimon <laurentsimon@google.com>
2023-03-02 21:53:29 +00:00

56 lines
1.1 KiB
Go

package utils
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
)
func Test_DecodeSignature(t *testing.T) {
t.Parallel()
tests := []struct {
name string
encoded string
decoded string
expected error
}{
{
name: "std encoding",
encoded: "YWJjMTIzIT8kKiYoKSctPUB+",
decoded: "abc123!?$*&()'-=@~",
},
{
name: "URL encoding",
encoded: "YWJjMTIzIT8kKiYoKSctPUB-",
decoded: "abc123!?$*&()'-=@~",
},
{
name: "invalid",
encoded: "invalid encoding",
expected: serrors.ErrorInvalidEncoding,
},
}
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
c, err := DecodeSignature(tt.encoded)
if !cmp.Equal(err, tt.expected, cmpopts.EquateErrors()) {
t.Errorf(cmp.Diff(err, tt.expected, cmpopts.EquateErrors()))
}
if err != nil {
return
}
cs := string(c)
if cs != tt.decoded {
t.Errorf(cmp.Diff(cs, tt.decoded))
}
})
}
}