ci / verify (push) Canceled after 0s
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package devicefleet
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewDownloadTicketIsCompactAndCanonical(t *testing.T) {
|
|
token, digest, address, expiresAt, err := newDownloadTicket("https://82.157.201.114")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(token) != 22 || len(digest) != 32 || len(address) > 64 || address != "https://82.157.201.114/f/"+token {
|
|
t.Fatalf("token=%q digest=%d address=%q", token, len(digest), address)
|
|
}
|
|
if expiresAt.IsZero() {
|
|
t.Fatal("ticket expiry was not set")
|
|
}
|
|
if _, err = downloadTokenHash(token); err != nil {
|
|
t.Fatal("generated token was rejected", err)
|
|
}
|
|
}
|
|
|
|
func TestDownloadTicketRejectsMalformedInput(t *testing.T) {
|
|
for _, token := range []string{"", "not-base64!", strings.Repeat("a", 21), strings.Repeat("a", 23), strings.Repeat("A", 24) + "=="} {
|
|
if _, err := downloadTokenHash(token); !errors.Is(err, ErrDownloadTicketUnavailable) {
|
|
t.Fatalf("token %q returned %v", token, err)
|
|
}
|
|
}
|
|
if _, err := shortDownloadURL("ftp://example.test", strings.Repeat("a", 22)); err == nil {
|
|
t.Fatal("non-HTTP download origin accepted")
|
|
}
|
|
if _, err := shortDownloadURL("https://example.test/base", strings.Repeat("a", 22)); err == nil {
|
|
t.Fatal("download origin with a path accepted")
|
|
}
|
|
}
|