Checks username and password against the wiki.
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

6 years ago
6 years ago
  1. package wikiauth_test
  2. import (
  3. "encoding/json"
  4. "os"
  5. "testing"
  6. "git.aiterp.net/aiterp/wikiauth"
  7. )
  8. func TestAuth(t *testing.T) {
  9. auth := struct {
  10. Username string
  11. Password string
  12. }{}
  13. file, err := os.Open("./credementials.json")
  14. if err != nil {
  15. t.Skip(err)
  16. return
  17. }
  18. err = json.NewDecoder(file).Decode(&auth)
  19. if err != nil {
  20. t.Skip(err)
  21. return
  22. }
  23. wiki := wikiauth.New("https://wiki.aiterp.net/api.php")
  24. err = wiki.Login(auth.Username, auth.Password)
  25. if err != nil {
  26. t.Error(err)
  27. }
  28. err = wiki.Login(auth.Username+"_wrong", auth.Password)
  29. if err == nil {
  30. t.Error("Wrong username accepted!")
  31. }
  32. err = wiki.Login(auth.Username, auth.Password+"_wrong")
  33. if err == nil {
  34. t.Error("Wrong password accepted!")
  35. }
  36. err = wiki.Login(auth.Username, "")
  37. if err == nil {
  38. t.Error("No password accepted!")
  39. }
  40. err = wiki.Login("", auth.Password)
  41. if err == nil {
  42. t.Error("No username accepted!")
  43. }
  44. err = wiki.Login("", "")
  45. if err == nil {
  46. t.Error("No credementials accepted!")
  47. }
  48. }