mirror of
https://gitgud.io/yats/libkiwi.git
synced 2026-06-28 23:12:04 -04:00
Fix IsLoggedIn() and some other error checking
This commit is contained in:
@@ -123,7 +123,8 @@ func (kf *KF) TwoFactorAuth(ctx context.Context, resp *http.Response, code uint3
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (kf *KF) IsLoggedIn() bool {
|
func (kf *KF) IsLoggedIn() bool {
|
||||||
return kf.Cookies.GetCookie(kf.domain, "xf_user") != nil
|
cookie := kf.Cookies.GetCookie(kf.domain, "xf_user")
|
||||||
|
return !(cookie == nil || cookie.Value == "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kf *KF) RefreshSession(ctx context.Context) (string, error) {
|
func (kf *KF) RefreshSession(ctx context.Context) (string, error) {
|
||||||
@@ -142,8 +143,8 @@ func (kf *KF) RefreshSession(ctx context.Context) (string, error) {
|
|||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
session := kf.Cookies.GetCookie(kf.domain, COOKIE_NAME)
|
session := kf.Cookies.GetCookie(kf.domain, COOKIE_NAME)
|
||||||
if session == nil {
|
if session == nil || session.Value == "" {
|
||||||
return "", errors.New("Failed to get new xf_session cookie.")
|
return "", fmt.Errorf("Failed to get new %s cookie", COOKIE_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.Value, nil
|
return session.Value, nil
|
||||||
|
|||||||
@@ -64,12 +64,19 @@ func TestLogin(t *testing.T) {
|
|||||||
t.Logf("2FA response: %+v\n", lr)
|
t.Logf("2FA response: %+v\n", lr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Logf("Checking RefreshSession()")
|
||||||
session, err := kf.RefreshSession(ctx)
|
session, err := kf.RefreshSession(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Logf("xf_session: %s\n", session)
|
t.Logf("xf_session: %s\n", session)
|
||||||
|
|
||||||
|
t.Logf("Checking IsLoggedIn()\n")
|
||||||
|
if !kf.IsLoggedIn() {
|
||||||
|
t.Error("IsLoggedIn() test returned false.")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func genTest2FACode() (uint32, error) {
|
func genTest2FACode() (uint32, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user