mirror of
https://github.com/slsa-framework/slsa-verifier.git
synced 2026-05-17 22:16:53 +00:00
* 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>
56 lines
1.1 KiB
Go
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))
|
|
}
|
|
})
|
|
}
|
|
}
|