Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add warning info, clean dependency and add expired token generate test #142

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> WARNING(Chinese only): 本项目受福州大学统一指导,由福州大学计算机与大数据学院、福州大学网络安全与信息化办公室管理(以上单位合称"官方")。这份源代码使用了宽松开源协议,但源码仅供学习参考,不允许该项目直接或间接性使用/修改后使用在任何非官方和 west2-online 外的应用、网站、app 及任何可以与用户产生交互的互联网信息媒介中。该警告具备行政约束效力。

<div align="center">
<h1 style="display: inline-block; vertical-align: middle;">fzuhelper-server</h1>
</div>
Expand Down
34 changes: 34 additions & 0 deletions api/mw/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,47 @@ package mw
import (
"fmt"
"testing"
"time"

"github.com/bytedance/mockey"
"github.com/golang-jwt/jwt"
"github.com/stretchr/testify/assert"

"github.com/west2-online/fzuhelper-server/pkg/constants"
)

// TestCreateExpiredToken 是一个特殊测试,旨在生成一个过期的 Token
func TestCreateExpiredToken(t *testing.T) {
// 默认生成时间是一年一个月七天前的
curTime := time.Now().AddDate(-1, -1, -7)
expiredTime := curTime.Add(constants.AccessTokenTTL)
var token string
var err error

claims := Claims{
Type: constants.TypeAccessToken,
StandardClaims: jwt.StandardClaims{
ExpiresAt: expiredTime.Unix(), // 过期时间戳
IssuedAt: curTime.Unix(), // 当前时间戳
Issuer: constants.Issuer, // 颁发者签名
},
}
tokenStruct := jwt.NewWithClaims(jwt.SigningMethodEdDSA, claims)
key, err := jwt.ParseEdPrivateKeyFromPEM([]byte(fmt.Sprintf("%v\n%v\n%v", "-----BEGIN PRIVATE KEY-----",
"此处需要修改为私钥",
"-----END PRIVATE KEY-----")))
if err != nil {
t.Errorf("parse private key failed, err: %v", err)
}

token, err = tokenStruct.SignedString(key)
if err != nil {
t.Errorf("sign token failed, err: %v", err)
}

fmt.Printf("Access-Token: %s", token)
}

func TestCreateAllToken(t *testing.T) {
type testCase struct {
name string
Expand Down
2 changes: 2 additions & 0 deletions docs/README.zh.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> 警告: 本项目受福州大学统一指导,由福州大学计算机与大数据学院、福州大学网络安全与信息化办公室管理(以上单位合称"官方")。这份源代码使用了宽松开源协议,但源码仅供学习参考,不允许该项目直接或间接性使用/修改后使用在任何非官方和 west2-online 外的应用、网站、app 及任何可以与用户产生交互的互联网信息媒介中。该警告具备行政约束效力。

<div align="center">
<h1 style="display: inline-block; vertical-align: middle;">fzuhelper-server</h1>
</div>
Expand Down
48 changes: 22 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,43 @@ replace github.com/apache/thrift => github.com/apache/thrift v0.13.0
require (
github.com/alibaba/sentinel-golang v1.0.4
github.com/apache/thrift v0.21.0
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/mockey v1.2.13
github.com/cloudwego/gopkg v0.1.3
github.com/cloudwego/hertz v0.9.3
github.com/cloudwego/hertz v0.9.4
github.com/cloudwego/kitex v0.12.0
github.com/elastic/go-elasticsearch v0.0.0
github.com/fsnotify/fsnotify v1.8.0
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/h2non/filetype v1.1.3
github.com/hertz-contrib/cors v0.1.0
github.com/hertz-contrib/gzip v0.0.3
github.com/hertz-contrib/opensergo v0.0.1
github.com/kitex-contrib/obs-opentelemetry/logging/zap v0.0.0-20241120035129-55da83caab1b
github.com/kitex-contrib/registry-etcd v0.2.5
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/redis/go-redis/v9 v9.7.0
github.com/segmentio/kafka-go v0.4.47
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
github.com/spf13/viper v1.19.0
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect
github.com/upyun/go-sdk/v3 v3.0.4
github.com/west2-online/jwch v0.2.0
gopkg.in/yaml.v2 v2.4.0 // indirect
gorm.io/driver/mysql v1.5.7
gorm.io/gorm v1.25.12
k8s.io/client-go v0.32.0
)

require (
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/auth v0.12.1 // indirect
cloud.google.com/go v0.117.0 // indirect
cloud.google.com/go/auth v0.13.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
cloud.google.com/go/compute/metadata v0.6.0 // indirect
cloud.google.com/go/firestore v1.17.0 // indirect
cloud.google.com/go/longrunning v0.6.3 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/andeya/ameda v1.5.3 // indirect
github.com/andeya/goutil v1.0.1 // indirect
github.com/antchfx/htmlquery v1.3.3 // indirect
github.com/antchfx/xpath v1.3.2 // indirect
github.com/antchfx/xpath v1.3.3 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bufbuild/protocompile v0.14.1 // indirect
github.com/bytedance/go-tagexpr/v2 v2.9.11 // indirect
github.com/bytedance/gopkg v0.1.1
github.com/bytedance/sonic v1.12.5
github.com/bytedance/sonic v1.12.6
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
Expand All @@ -78,6 +65,7 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-resty/resty/v2 v2.16.2 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand All @@ -87,6 +75,7 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
github.com/gopherjs/gopherjs v1.12.80 // indirect
Expand Down Expand Up @@ -124,9 +113,14 @@ require (
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sagikazarmark/crypt v0.27.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/smartystreets/goconvey v1.7.2 // indirect
Expand All @@ -139,12 +133,13 @@ require (
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
go.etcd.io/etcd/api/v3 v3.5.17 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.17 // indirect
go.etcd.io/etcd/client/v2 v2.305.17 // indirect
go.etcd.io/etcd/client/v3 v3.5.17 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
Expand All @@ -154,20 +149,21 @@ require (
go.uber.org/zap v1.27.0
golang.org/x/arch v0.12.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.10.0
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0
google.golang.org/api v0.211.0 // indirect
google.golang.org/genproto v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/api v0.212.0 // indirect
google.golang.org/genproto v0.0.0-20241216192217-9240e9c98484 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241216192217-9240e9c98484 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484 // indirect
google.golang.org/grpc v1.69.0 // indirect
google.golang.org/protobuf v1.35.2 // indirect
google.golang.org/protobuf v1.36.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apimachinery v0.32.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
Expand Down
Loading
Loading