final bad try
This commit is contained in:
parent
b540edbe1e
commit
fa5e0287e5
7 changed files with 106 additions and 1 deletions
39
golang-fuzz/auth_fuzz.go
Normal file
39
golang-fuzz/auth_fuzz.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package my_golang_fuzz
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"linux-auth/internal/auth"
|
||||
"linux-auth/internal/db"
|
||||
)
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
if err := db.Init("test_data.db"); err != nil {
|
||||
return -1
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
parts := bytes.SplitN(data, []byte{0}, 2)
|
||||
if len(parts) != 2 {
|
||||
return 0
|
||||
}
|
||||
|
||||
username := string(parts[0])
|
||||
password := string(parts[1])
|
||||
|
||||
ok, err := auth.Authenticate(username, password)
|
||||
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
if ok {
|
||||
if (username == "admin" && password == "admin123") ||
|
||||
(username == "user1" && password == "password1") {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue