Skip to content

Commit

Permalink
Fix skip cache error (#732)
Browse files Browse the repository at this point in the history
* Fix skip cache error

* Delete token cache when failed to get email

---------

Co-authored-by: 杨赫然 <[email protected]>
  • Loading branch information
feiniks and 杨赫然 authored Dec 30, 2024
1 parent ee9ad5e commit e2d7718
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions fileserver/sync_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1287,13 +1287,15 @@ func validateToken(r *http.Request, repoID string, skipCache bool) (string, *app
}
}

if value, ok := tokenCache.Load(token); ok {
if info, ok := value.(*tokenInfo); ok {
if info.repoID != repoID {
msg := "Invalid token"
return "", &appError{nil, msg, http.StatusForbidden}
if !skipCache {
if value, ok := tokenCache.Load(token); ok {
if info, ok := value.(*tokenInfo); ok {
if info.repoID != repoID {
msg := "Invalid token"
return "", &appError{nil, msg, http.StatusForbidden}
}
return info.email, nil
}
return info.email, nil
}
}

Expand All @@ -1304,6 +1306,7 @@ func validateToken(r *http.Request, repoID string, skipCache bool) (string, *app
return email, &appError{err, "", http.StatusInternalServerError}
}
if email == "" {
tokenCache.Delete(token)
msg := fmt.Sprintf("Failed to get email by token %s", token)
return email, &appError{nil, msg, http.StatusForbidden}
}
Expand Down

0 comments on commit e2d7718

Please sign in to comment.