mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
fix: gen code generator; some unit tests
This commit is contained in:
parent
33a996e777
commit
918f920d57
8 changed files with 86 additions and 178 deletions
|
@ -152,11 +152,13 @@ func FinishPasskeyLogin(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secureSessionID := user.SetSecureSessionID(outUser.ID)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, LoginResponse{
|
c.JSON(http.StatusOK, LoginResponse{
|
||||||
Code: LoginSuccess,
|
Code: LoginSuccess,
|
||||||
Message: "ok",
|
Message: "ok",
|
||||||
Token: token,
|
Token: token,
|
||||||
// SecureSessionID: secureSessionID,
|
SecureSessionID: secureSessionID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,9 +167,12 @@ async function handlePasskeyLogin() {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (r.token) {
|
if (r.token) {
|
||||||
|
const cookies = useCookies(['nginx-ui-2fa'])
|
||||||
const next = (route.query?.next || '').toString() || '/'
|
const next = (route.query?.next || '').toString() || '/'
|
||||||
|
|
||||||
passkeyLogin(asseResp.rawId, r.token)
|
passkeyLogin(asseResp.rawId, r.token)
|
||||||
|
secureSessionId.value = r.secure_session_id
|
||||||
|
cookies.set('secure_session_id', r.secure_session_id, { maxAge: 60 * 3 })
|
||||||
|
|
||||||
await router.push(next)
|
await router.push(next)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/0xJacky/Nginx-UI/model"
|
"github.com/0xJacky/Nginx-UI/model"
|
||||||
"github.com/0xJacky/Nginx-UI/settings"
|
"github.com/uozi-tech/cosy/settings"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gen"
|
"gorm.io/gen"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
@ -21,26 +21,26 @@ func main() {
|
||||||
Mode: gen.WithoutContext | gen.WithDefaultQuery,
|
Mode: gen.WithoutContext | gen.WithDefaultQuery,
|
||||||
//if you want the nullable field generation property to be pointer type, set FieldNullable true
|
//if you want the nullable field generation property to be pointer type, set FieldNullable true
|
||||||
FieldNullable: true,
|
FieldNullable: true,
|
||||||
//if you want to assign field which has default value in `Create` API, set FieldCoverable true, reference: https://gorm.io/docs/create.html#Default-Values
|
//if you want to assign field which has the default value in `Create` API, set FieldCoverable true, reference: https://gorm.io/docs/create.html#Default-Values
|
||||||
FieldCoverable: true,
|
FieldCoverable: true,
|
||||||
// if you want to generate field with unsigned integer type, set FieldSignable true
|
// if you want to generate field with an unsigned integer type, set FieldSignable true
|
||||||
/* FieldSignable: true,*/
|
/* FieldSignable: true,*/
|
||||||
//if you want to generate index tags from database, set FieldWithIndexTag true
|
//if you want to generate index tags from the database, set FieldWithIndexTag true
|
||||||
/* FieldWithIndexTag: true,*/
|
/* FieldWithIndexTag: true,*/
|
||||||
//if you want to generate type tags from database, set FieldWithTypeTag true
|
//if you want to generate type tags from the database, set FieldWithTypeTag true
|
||||||
/* FieldWithTypeTag: true,*/
|
/* FieldWithTypeTag: true,*/
|
||||||
//if you need unit tests for query code, set WithUnitTest true
|
//if you need unit tests for query code, set WithUnitTest true
|
||||||
/* WithUnitTest: true, */
|
/* WithUnitTest: true, */
|
||||||
})
|
})
|
||||||
|
|
||||||
// reuse the database connection in Project or create a connection here
|
// reuse the database connection in Project or create a connection here
|
||||||
// if you want to use GenerateModel/GenerateModelAs, UseDB is necessary or it will panic
|
// if you want to use GenerateModel/GenerateModelAs, UseDB is necessary, or it will panic
|
||||||
var confPath string
|
var confPath string
|
||||||
flag.StringVar(&confPath, "config", "app.ini", "Specify the configuration file")
|
flag.StringVar(&confPath, "config", "app.ini", "Specify the configuration file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
settings.Init(confPath)
|
settings.Init(confPath)
|
||||||
dbPath := path.Join(path.Dir(settings.ConfPath), fmt.Sprintf("%s.db", settings.ServerSettings.Database))
|
dbPath := path.Join(path.Dir(confPath), fmt.Sprintf("%s.db", settings.DataBaseSettings.Name))
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
|
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
|
||||||
|
@ -56,7 +56,7 @@ func main() {
|
||||||
g.UseDB(db)
|
g.UseDB(db)
|
||||||
|
|
||||||
// apply basic crud api on structs or table models which is specified by table name with function
|
// apply basic crud api on structs or table models which is specified by table name with function
|
||||||
// GenerateModel/GenerateModelAs. And generator will generate table models' code when calling Excute.
|
// GenerateModel/GenerateModelAs. And the generator will generate table models' code when calling Excute.
|
||||||
g.ApplyBasic(model.GenerateAllModel()...)
|
g.ApplyBasic(model.GenerateAllModel()...)
|
||||||
|
|
||||||
// apply diy interfaces on structs or table models
|
// apply diy interfaces on structs or table models
|
||||||
|
|
|
@ -3,11 +3,13 @@ package cluster
|
||||||
import (
|
import (
|
||||||
"github.com/0xJacky/Nginx-UI/settings"
|
"github.com/0xJacky/Nginx-UI/settings"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/uozi-tech/cosy/sandbox"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_parseNodeUrl(t *testing.T) {
|
func Test_parseNodeUrl(t *testing.T) {
|
||||||
settings.Init("../../app.example.ini")
|
sandbox.NewInstance("../../app.example.ini", "sqlite").
|
||||||
|
Run(func(instance *sandbox.Instance) {
|
||||||
t.Log(settings.ClusterSettings.Node)
|
t.Log(settings.ClusterSettings.Node)
|
||||||
node := settings.ClusterSettings.Node[0]
|
node := settings.ClusterSettings.Node[0]
|
||||||
|
|
||||||
|
@ -44,4 +46,5 @@ func Test_parseNodeUrl(t *testing.T) {
|
||||||
assert.Equal(t, "http://10.0.0.3", env.URL)
|
assert.Equal(t, "http://10.0.0.3", env.URL)
|
||||||
assert.Equal(t, "my-node-secret", env.Token)
|
assert.Equal(t, "my-node-secret", env.Token)
|
||||||
assert.Equal(t, true, env.Enabled)
|
assert.Equal(t, true, env.Enabled)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package cron
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/0xJacky/Nginx-UI/internal/kernal"
|
|
||||||
"github.com/0xJacky/Nginx-UI/settings"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRestartLogrotate(t *testing.T) {
|
|
||||||
settings.Init("../../app.ini")
|
|
||||||
|
|
||||||
kernal.InitDatabase()
|
|
||||||
|
|
||||||
InitCronJobs()
|
|
||||||
|
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
|
|
||||||
RestartLogrotate()
|
|
||||||
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
[app]
|
|
||||||
PageSize = 20
|
|
||||||
JwtSecret = newSecret
|
|
||||||
|
|
||||||
[server]
|
|
||||||
Host = 0.0.0.0
|
|
||||||
Port = 9000
|
|
||||||
RunMode = debug
|
|
||||||
|
|
||||||
[database]
|
|
||||||
Host =
|
|
||||||
Port = 0
|
|
||||||
User =
|
|
||||||
Password =
|
|
||||||
Name = database
|
|
||||||
TablePrefix =
|
|
||||||
|
|
||||||
[auth]
|
|
||||||
IPWhiteList = 127.0.0.1
|
|
||||||
BanThresholdMinutes = 10
|
|
||||||
MaxAttempts = 10
|
|
||||||
|
|
||||||
[casdoor]
|
|
||||||
Endpoint = http://127.0.0.1:8001
|
|
||||||
ClientId = 1234567890qwertyuiop
|
|
||||||
ClientSecret = 1234567890qwertyuiop1234567890qwertyuiop
|
|
||||||
CertificatePath = ./casdoor.pub
|
|
||||||
Organization = built-in
|
|
||||||
Application = nginx-ui-dev
|
|
||||||
RedirectUri =
|
|
||||||
|
|
||||||
[cert]
|
|
||||||
Email = test
|
|
||||||
CADir = /test
|
|
||||||
CertRenewalInterval = 7
|
|
||||||
RecursiveNameservers = 8.8.8.8,1.1.1.1
|
|
||||||
HTTPChallengePort = 9181
|
|
||||||
|
|
||||||
[cluster]
|
|
||||||
Node = http://10.0.0.1:9000?name=test&node_secret=asdfghjklqwertyuiopzxcvbnm&enabled=true
|
|
||||||
|
|
||||||
[crypto]
|
|
||||||
Secret = 12345678901234567890
|
|
||||||
|
|
||||||
[http]
|
|
||||||
GithubProxy = https://mirror.ghproxy.com/
|
|
||||||
InsecureSkipVerify = true
|
|
||||||
|
|
||||||
[logrotate]
|
|
||||||
Enabled = true
|
|
||||||
CMD = logrotate /etc/logrotate.d/nginx
|
|
||||||
Interval = 1440
|
|
||||||
|
|
||||||
[nginx]
|
|
||||||
AccessLogPath =
|
|
||||||
ErrorLogPath =
|
|
||||||
LogDirWhiteList = /var/log/nginx
|
|
||||||
ConfigDir =
|
|
||||||
PIDPath =
|
|
||||||
TestConfigCmd =
|
|
||||||
ReloadCmd =
|
|
||||||
RestartCmd =
|
|
||||||
|
|
||||||
[node]
|
|
||||||
Name = Local
|
|
||||||
Secret =
|
|
||||||
SkipInstallation = false
|
|
||||||
Demo = false
|
|
||||||
|
|
||||||
[openai]
|
|
||||||
BaseUrl =
|
|
||||||
Token =
|
|
||||||
Proxy =
|
|
||||||
Model = gpt-4o
|
|
||||||
|
|
||||||
[terminal]
|
|
||||||
StartCmd = bash
|
|
||||||
|
|
||||||
[webauthn]
|
|
||||||
RPDisplayName = Nginx UI
|
|
||||||
RPID = localhost
|
|
||||||
RPOrigins = http://localhost:3002,http://127.0.0.1:3002
|
|
|
@ -39,7 +39,7 @@ func TestSetup(t *testing.T) {
|
||||||
// Cert
|
// Cert
|
||||||
_ = os.Setenv("NGINX_UI_CERT_EMAIL", "test")
|
_ = os.Setenv("NGINX_UI_CERT_EMAIL", "test")
|
||||||
_ = os.Setenv("NGINX_UI_CERT_CA_DIR", "/test/ca")
|
_ = os.Setenv("NGINX_UI_CERT_CA_DIR", "/test/ca")
|
||||||
_ = os.Setenv("NGINX_UI_CERT_CERT_RENEWAL_INTERVAL", "14")
|
_ = os.Setenv("NGINX_UI_CERT_RENEWAL_INTERVAL", "14")
|
||||||
_ = os.Setenv("NGINX_UI_CERT_RECURSIVE_NAMESERVERS", "8.8.8.8,1.1.1.1")
|
_ = os.Setenv("NGINX_UI_CERT_RECURSIVE_NAMESERVERS", "8.8.8.8,1.1.1.1")
|
||||||
_ = os.Setenv("NGINX_UI_CERT_HTTP_CHALLENGE_PORT", "1080")
|
_ = os.Setenv("NGINX_UI_CERT_HTTP_CHALLENGE_PORT", "1080")
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ func TestSetup(t *testing.T) {
|
||||||
|
|
||||||
// Node
|
// Node
|
||||||
_ = os.Setenv("NGINX_UI_NODE_NAME", "test")
|
_ = os.Setenv("NGINX_UI_NODE_NAME", "test")
|
||||||
_ = os.Setenv("NGINX_UI_NODE_NODE_SECRET", "nodeSecret")
|
_ = os.Setenv("NGINX_UI_NODE_SECRET", "nodeSecret")
|
||||||
_ = os.Setenv("NGINX_UI_NODE_SKIP_INSTALLATION", "true")
|
_ = os.Setenv("NGINX_UI_NODE_SKIP_INSTALLATION", "true")
|
||||||
_ = os.Setenv("NGINX_UI_NODE_DEMO", "true")
|
_ = os.Setenv("NGINX_UI_NODE_DEMO", "true")
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,15 @@ import (
|
||||||
"github.com/0xJacky/Nginx-UI/settings"
|
"github.com/0xJacky/Nginx-UI/settings"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sashabaranov/go-openai"
|
"github.com/sashabaranov/go-openai"
|
||||||
|
"github.com/uozi-tech/cosy/sandbox"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChatGPT(t *testing.T) {
|
func TestChatGPT(t *testing.T) {
|
||||||
settings.Init("../../app.ini")
|
sandbox.NewInstance("../../app.ini", "sqlite").
|
||||||
|
Run(func(instance *sandbox.Instance) {
|
||||||
c := openai.NewClient(settings.OpenAISettings.Token)
|
c := openai.NewClient(settings.OpenAISettings.Token)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
@ -48,4 +50,6 @@ func TestChatGPT(t *testing.T) {
|
||||||
fmt.Printf("%v", response.Choices[0].Delta.Content)
|
fmt.Printf("%v", response.Choices[0].Delta.Content)
|
||||||
_ = os.Stdout.Sync()
|
_ = os.Stdout.Sync()
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue