Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Allow clearing mobile lock screen password without OIDC https://github.com/siyuan-note/siyuan/issues/18542

Daniel15e3ece11ecf
diff --git a/kernel/api/system.go b/kernel/api/system.go
index beb139c379..009d175151 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -910,7 +910,7 @@ func setAccessAuthCode(c *gin.Context) {
if aac == "" {
currentOIDC := model.Conf.GetOIDC()
var err error
- if util.IsMobileContainer() {
+ if util.IsMobileContainer() && currentOIDC.Enabled {
err = model.ValidateOIDCMobileConfiguration(currentOIDC)
} else if !model.IsLocalRequest(c) {
err = model.ValidateOIDCConfigurationChange(c.Request.Context(), currentOIDC, true, false,
diff --git a/kernel/api/system_test.go b/kernel/api/system_test.go
index 9f9342f497..51bc1382ca 100644
--- a/kernel/api/system_test.go
+++ b/kernel/api/system_test.go
@@ -23,6 +23,8 @@ import (
"strings"
"testing"
+ ginSessions "github.com/gin-contrib/sessions"
+ "github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/model"
@@ -148,6 +150,44 @@ func TestSetAccessAuthCodeRejectsUnsupportedMobileOIDC(t *testing.T) {
}
}
+func TestSetAccessAuthCodeAllowsClearingOnMobileWithoutOIDC(t *testing.T) {
+ gin.SetMode(gin.TestMode)
+ previousConf := model.Conf
+ previousReadOnly := util.ReadOnly
+ previousContainer := util.Container
+ model.Conf = model.NewAppConf()
+ model.Conf.CookieKey = "mobile-clear-access-auth-api-test-cookie-key"
+ model.Conf.AccessAuthCode = "existing-code"
+ util.ReadOnly = true
+ util.Container = util.ContainerAndroid
+ t.Cleanup(func() {
+ model.Conf = previousConf
+ util.ReadOnly = previousReadOnly
+ util.Container = previousContainer
+ })
+
+ engine := gin.New()
+ store := cookie.NewStore([]byte("mobile-clear-access-auth-api-test-session-key"))
+ engine.Use(ginSessions.Sessions("siyuan", store))
+ engine.POST("/api/system/setAccessAuthCode", setAccessAuthCode)
+ recorder := httptest.NewRecorder()
+ request := httptest.NewRequest(http.MethodPost, "http://127.0.0.1/api/system/setAccessAuthCode",
+ strings.NewReader(`{"accessAuthCode":""}`))
+ request.RemoteAddr = "127.0.0.1:1234"
+ request.Header.Set("Content-Type", "application/json")
+ engine.ServeHTTP(recorder, request)
+
+ response := &struct {
+ Code int `json:"code"`
+ }{}
+ if err := json.Unmarshal(recorder.Body.Bytes(), response); err != nil {
+ t.Fatalf("unmarshal mobile setAccessAuthCode response failed: %v", err)
+ }
+ if response.Code != 0 || model.Conf.AccessAuthCode != "" {
+ t.Fatalf("clearing mobile access authentication without OIDC failed: %s", recorder.Body.String())
+ }
+}
+
func TestGetConfUILayoutByRole(t *testing.T) {
gin.SetMode(gin.TestMode)