password_test.go
| 1 | package db |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | func TestVerifyPasswordWaitsForArgonSlot(t *testing.T) { |
| 9 | for range cap(argonSlots) { |
| 10 | argonSlots <- struct{}{} |
| 11 | } |
| 12 | done := make(chan bool) |
| 13 | go func() { |
| 14 | ok, _ := VerifyPassword(npmHash, "testpass123") |
| 15 | done <- ok |
| 16 | }() |
| 17 | select { |
| 18 | case <-done: |
| 19 | t.Fatal("VerifyPassword ran while every slot was taken") |
| 20 | case <-time.After(100 * time.Millisecond): |
| 21 | } |
| 22 | for range cap(argonSlots) { |
| 23 | <-argonSlots |
| 24 | } |
| 25 | if !<-done { |
| 26 | t.Fatal("VerifyPassword rejected the right password") |
| 27 | } |
| 28 | } |
| 29 |