Compare commits
1
Commits
main
...
fix/1439-replay
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef76b9f2ea |
@@ -4,11 +4,8 @@ package outward
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -166,33 +163,6 @@ func TestCheckSecretLetsACamelCaseNameThrough(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1439/AC1: a name written in lowercase words and digits between `-`, `_` or `/`, every piece short, is a
|
|
||||||
// name and not a secret: mesh-issues' owners list (the catalogue's 134 defaults plus okioki) was refused
|
|
||||||
// whole as "a long random-looking string" for modules/asus-zephyrus-g14, i3status-rust and powerlevel10k.
|
|
||||||
func TestCheckSecretLetsALowercaseNameWithDigitsThrough(t *testing.T) {
|
|
||||||
for _, text := range []string{
|
|
||||||
"mesh-catalog modules/asus-zephyrus-g14",
|
|
||||||
"mesh-catalog modules/i3status-rust",
|
|
||||||
"mesh-catalog modules/powerlevel10k",
|
|
||||||
} {
|
|
||||||
if r, ok := CheckSecret(text); !ok {
|
|
||||||
t.Errorf("CheckSecret(%q) withheld it: %s", text, r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
raw, err := os.ReadFile(filepath.Join("testdata", "owners-1439.json"))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
var owners []string
|
|
||||||
if err := json.Unmarshal(raw, &owners); err != nil || len(owners) != 135 {
|
|
||||||
t.Fatalf("testdata holds %d owners (%v), want the 134 defaults plus okioki", len(owners), err)
|
|
||||||
}
|
|
||||||
compact, _ := json.Marshal(owners)
|
|
||||||
if r, ok := CheckSecret("+ owners: " + string(compact)); !ok {
|
|
||||||
t.Errorf("CheckSecret withheld the owners list: %s", r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1439/AC2: what looks random is still refused: a mixed-case run, a base64url token with `-` and `_`, a
|
// 1439/AC2: what looks random is still refused: a mixed-case run, a base64url token with `-` and `_`, a
|
||||||
// lowercase run of letters and digits with no separator, and a lowercase name with one long random piece.
|
// lowercase run of letters and digits with no separator, and a lowercase name with one long random piece.
|
||||||
func TestCheckSecretStillRefusesRandomRunsBesideNames(t *testing.T) {
|
func TestCheckSecretStillRefusesRandomRunsBesideNames(t *testing.T) {
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package outward
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestReplay1439 is issue 1439, replayed (mesh-lab R1439, novox/hq ADR 0237 §5), written only with what the
|
||||||
|
// package had before its fix: it fails on the commit before mesh-sdk #52 and passes on it.
|
||||||
|
//
|
||||||
|
// 1439/AC1: a name written in lowercase words and digits between `-`, `_` or `/`, every piece short, is a
|
||||||
|
// name and not a secret: mesh-issues' owners list (the catalogue's 134 defaults plus okioki) was refused
|
||||||
|
// whole as "a long random-looking string" for modules/asus-zephyrus-g14, i3status-rust and powerlevel10k.
|
||||||
|
func TestReplay1439(t *testing.T) {
|
||||||
|
for _, text := range []string{
|
||||||
|
"mesh-catalog modules/asus-zephyrus-g14",
|
||||||
|
"mesh-catalog modules/i3status-rust",
|
||||||
|
"mesh-catalog modules/powerlevel10k",
|
||||||
|
} {
|
||||||
|
if r, ok := CheckSecret(text); !ok {
|
||||||
|
t.Errorf("CheckSecret(%q) withheld it: %s", text, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raw, err := os.ReadFile("replay1439_owners.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var owners []string
|
||||||
|
if err := json.Unmarshal(raw, &owners); err != nil || len(owners) != 135 {
|
||||||
|
t.Fatalf("testdata holds %d owners (%v), want the 134 defaults plus okioki", len(owners), err)
|
||||||
|
}
|
||||||
|
compact, _ := json.Marshal(owners)
|
||||||
|
if r, ok := CheckSecret("+ owners: " + string(compact)); !ok {
|
||||||
|
t.Errorf("CheckSecret withheld the owners list: %s", r)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user