MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestHash

Function TestHash

pkg/auth/password_test.go:27–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestHash(t *testing.T) {
28 a := assertions.New(t)
29
30 ctx := NewContextWithHashValidator(test.Context(), pbkdf2.Default())
31
32 plain := "secret"
33
34 p, err := Hash(ctx, plain)
35 a.So(err, should.BeNil)
36
37 {
38 ok, err := Validate(p, plain)
39 a.So(err, should.BeNil)
40 a.So(ok, should.BeTrue)
41 }
42
43 {
44 ok, err := Validate(p, "somethingelse")
45 a.So(err, should.BeNil)
46 a.So(ok, should.BeFalse)
47 }
48
49 {
50 ok, err := Validate("foo", "somethingelse")
51 a.So(err, should.NotBeNil)
52 a.So(ok, should.BeFalse)
53 }
54
55 {
56 ok, err := Validate("LOL$foo", "somethingelse")
57 a.So(err, should.NotBeNil)
58 a.So(ok, should.BeFalse)
59 }
60
61 {
62 ok, err := Validate("PBKDF2$foo", "somethingelse")
63 a.So(err, should.NotBeNil)
64 a.So(ok, should.BeFalse)
65 }
66}
67
68func TestLegacy(t *testing.T) {
69 a := assertions.New(t)

Callers

nothing calls this directly

Calls 6

ContextFunction · 0.92
DefaultFunction · 0.92
HashFunction · 0.85
ValidateFunction · 0.85
NewMethod · 0.65

Tested by

no test coverage detected