~james/core

core/spindle/xrpc/validation_test.go -rw-r--r-- 761 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package xrpc

import (
	"strings"
	"testing"
)

func TestRequireSha(t *testing.T) {
	if err := requireSha(strings.Repeat("a", 40)); err != nil {
		t.Fatalf("valid SHA rejected: %v", err)
	}
	if err := requireSha(strings.Repeat("a", 64)); err != nil {
		t.Fatalf("valid sha256 commit hash rejected: %v", err)
	}
	for name, sha := range map[string]string{
		"short":         strings.Repeat("a", 39),
		"long":          strings.Repeat("a", 41),
		"between sizes": strings.Repeat("a", 50),
		"too long":      strings.Repeat("a", 65),
		"not hex":       strings.Repeat("z", 40),
		"uppercase":     strings.Repeat("A", 40),
	} {
		t.Run(name, func(t *testing.T) {
			if err := requireSha(sha); err == nil {
				t.Fatalf("invalid SHA %q accepted", sha)
			}
		})
	}
}