You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1017 B
58 lines
1017 B
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!")
|
|
}
|
|
}
|