|
|
@ -0,0 +1,58 @@ |
|
|
|
package wikiauth_test |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"os" |
|
|
|
"testing" |
|
|
|
|
|
|
|
"git.aiterp.net/AiteRP/wikiauth" |
|
|
|
) |
|
|
|
|
|
|
|
func TestAuth(t *testing.T) { |
|
|
|
auth := struct { |
|
|
|
Username string |
|
|
|
Password string |
|
|
|
}{} |
|
|
|
|
|
|
|
file, err := os.Open("./credementials.json") |
|
|
|
if err != nil { |
|
|
|
t.Skip(err) |
|
|
|
return |
|
|
|
} |
|
|
|
err = json.NewDecoder(file).Decode(&auth) |
|
|
|
if err != nil { |
|
|
|
t.Skip(err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
wiki := wikiauth.New("https://wiki.aiterp.net/api.php") |
|
|
|
err = wiki.Login(auth.Username, auth.Password) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
|
|
|
|
err = wiki.Login(auth.Username+"_wrong", auth.Password) |
|
|
|
if err == nil { |
|
|
|
t.Error("Wrong username accepted!") |
|
|
|
} |
|
|
|
|
|
|
|
err = wiki.Login(auth.Username, auth.Password+"_wrong") |
|
|
|
if err == nil { |
|
|
|
t.Error("Wrong password accepted!") |
|
|
|
} |
|
|
|
|
|
|
|
err = wiki.Login(auth.Username, "") |
|
|
|
if err == nil { |
|
|
|
t.Error("No password accepted!") |
|
|
|
} |
|
|
|
|
|
|
|
err = wiki.Login("", auth.Password) |
|
|
|
if err == nil { |
|
|
|
t.Error("No username accepted!") |
|
|
|
} |
|
|
|
|
|
|
|
err = wiki.Login("", "") |
|
|
|
if err == nil { |
|
|
|
t.Error("No credementials accepted!") |
|
|
|
} |
|
|
|
} |