Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4f247ec
Upgrade v1.13.1
hwbrzzl Sep 10, 2023
d174dcb
Merge #305, #306 to v1.13.x (#308)
hwbrzzl Oct 5, 2023
9d8d413
fix: [#270] Optimize postgres DNS (#309)
hwbrzzl Oct 5, 2023
2764972
fix: [#253] [Bug] The With method can't be used with the Cursor metho…
hwbrzzl Oct 7, 2023
7029daa
Upgrade v1.13.2
hwbrzzl Oct 7, 2023
b0e2048
Update README
hwbrzzl Oct 7, 2023
0f062d6
fix: Register multiple events (#317)
ahmed3mar Oct 12, 2023
f7d4278
fix: database variable (#316)
ahmed3mar Oct 12, 2023
e9d4978
feat: [#265] The Config module supports get system environment variab…
hwbrzzl Nov 2, 2023
e0020c2
feat: [#265] The Config module supports get system environment variab…
hwbrzzl Nov 5, 2023
f1b6148
Upgrade v1.13.3
hwbrzzl Nov 9, 2023
ecce87a
Update mock
hwbrzzl Nov 9, 2023
6838c07
Upgrade v1.13.4
hwbrzzl Nov 9, 2023
19331ce
fix: [#312] orm connection is not working (#354)
hwbrzzl Nov 28, 2023
fdfe5dd
fix: [#320] mock.Log() is not working (#355)
hwbrzzl Nov 28, 2023
25e4533
Upgrade v1.13.5 (#357)
hwbrzzl Nov 28, 2023
a7da329
fix: [#341] The Chain Query isn't executed one by one (#380)
hwbrzzl Dec 30, 2023
f4385e5
Upgrade v1.13.7
hwbrzzl Dec 30, 2023
87a80b3
fix: [#388] [Bug] data error when calling facades.Auth().Parse() mult…
hwbrzzl Apr 17, 2024
2aa80fb
feat: [#389] The queue log needs to be controled by APP_DEBUG (#459)
hwbrzzl Apr 18, 2024
94589ed
fix: [#390] The context that set by facades.Orm().WithContext() isn't…
hwbrzzl Apr 18, 2024
3f434c5
Upgrade v1.13.8
hwbrzzl Apr 18, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Install dependencies 📦
- name: Install dependencies
run: go mod tidy
- name: Run tests with coverage ✅
- name: Run tests with coverage
run: go test -v -coverprofile="coverage.out" ./...
- name: Upload coverage report to Codecov 📝
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.out
Expand Down
40 changes: 0 additions & 40 deletions .github/workflows/filesystem.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/mail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Install dependencies 📦
- name: Install dependencies
run: go mod tidy
- name: Run tests ✅
- name: Run tests
run: go test ./mail/...
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Example [https://github.com/goravel/example](https://github.com/goravel/example)
| [Grpc](https://www.goravel.dev/the-basics/grpc.html) | [Artisan Console](https://www.goravel.dev/digging-deeper/artisan-console.html) | [Task Scheduling](https://www.goravel.dev/digging-deeper/task-scheduling.html) | [Queue](https://www.goravel.dev/digging-deeper/queues.html) |
| [Event](https://www.goravel.dev/digging-deeper/event.html) | [FileStorage](https://www.goravel.dev/digging-deeper/filesystem.html) | [Mail](https://www.goravel.dev/digging-deeper/mail.html) | [Validation](https://www.goravel.dev/the-basics/validation.html) |
| [Mock](https://www.goravel.dev/digging-deeper/mock.html) | [Hash](https://www.goravel.dev/security/hashing.html) | [Crypt](https://www.goravel.dev/security/encryption.html) | [Carbon](https://www.goravel.dev/digging-deeper/helpers.html) |
| [Package Development](https://www.goravel.dev/digging-deeper/package-development.html) | [Testing](/testing/getting-started.html) | | |
| [Package Development](https://www.goravel.dev/digging-deeper/package-development.html) | [Testing](https://www.goravel.dev/testing/getting-started.html) | | |

## Roadmap

Expand All @@ -69,6 +69,14 @@ This project exists thanks to all the people who contribute, to participate in t
<a href="https://github.com/Marian0" target="_blank"><img src="https://avatars.githubusercontent.com/u/624592?v=4" width="48" height="48"></a>
<a href="https://github.com/ahmed3mar" target="_blank"><img src="https://avatars.githubusercontent.com/u/12982325?v=4" width="48" height="48"></a>
<a href="https://github.com/flc1125" target="_blank"><img src="https://avatars.githubusercontent.com/u/14297703?v=4" width="48" height="48"></a>
<a href="https://github.com/zzpwestlife" target="_blank"><img src="https://avatars.githubusercontent.com/u/12382180?v=4" width="48" height="48"></a>
<a href="https://github.com/juantarrel" target="_blank"><img src="https://avatars.githubusercontent.com/u/7213379?v=4" width="48" height="48"></a>

## Sponsor

Better development of the project is inseparable from your support, reward us by [Open Collective](https://opencollective.com/goravel).

<p align="left"><img src="https://www.goravel.dev/reward.png" width="200"></p>

## Group

Expand Down
24 changes: 16 additions & 8 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ Laravel!

## 主要功能

| | | | |
| ---------- | -------------- | -------------- | -------------- |
| [自定义配置](https://www.goravel.dev/zh/getting-started/configuration.html) | [HTTP 服务](https://www.goravel.dev/zh/the-basics/routing.html) | [用户认证](https://www.goravel.dev/zh/security/authentication.html) | [用户授权](https://www.goravel.dev/zh/security/authorization.html) |
| [数据库 ORM](https://www.goravel.dev/zh/ORM/getting-started.html) | [数据库迁移](https://www.goravel.dev/zh/ORM/migrations.html) | [日志](https://www.goravel.dev/zh/the-basics/logging.html) | [缓存](https://www.goravel.dev/zh/digging-deeper/cache.html) |
| [Grpc](https://www.goravel.dev/zh/the-basics/grpc.html) | [Artisan 命令行](https://www.goravel.dev/zh/digging-deeper/artisan-console.html) | [任务调度](https://www.goravel.dev/zh/digging-deeper/task-scheduling.html) | [队列](https://www.goravel.dev/zh/digging-deeper/queues.html) |
| [事件系统](https://www.goravel.dev/zh/digging-deeper/event.html) | [文件存储](https://www.goravel.dev/zh/digging-deeper/filesystem.html) | [邮件](https://www.goravel.dev/zh/digging-deeper/mail.html) | [表单验证](https://www.goravel.dev/zh/the-basics/validation.html) |
| [Mock](https://www.goravel.dev/zh/digging-deeper/mock.html) | [Hash](https://www.goravel.dev/zh/security/hashing.html) | [Crypt](https://www.goravel.dev/zh/security/encryption.html) | [Carbon](https://www.goravel.dev/zh/digging-deeper/helpers.html) |
| [扩展包开发](https://www.goravel.dev/zh/digging-deeper/package-development.html) | [测试](/testing/getting-started.html) | | |
| | | | |
|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------------------------------------------------------------------|------------------------------------------------------------------|
| [自定义配置](https://www.goravel.dev/zh/getting-started/configuration.html) | [HTTP 服务](https://www.goravel.dev/zh/the-basics/routing.html) | [用户认证](https://www.goravel.dev/zh/security/authentication.html) | [用户授权](https://www.goravel.dev/zh/security/authorization.html) |
| [数据库 ORM](https://www.goravel.dev/zh/ORM/getting-started.html) | [数据库迁移](https://www.goravel.dev/zh/ORM/migrations.html) | [日志](https://www.goravel.dev/zh/the-basics/logging.html) | [缓存](https://www.goravel.dev/zh/digging-deeper/cache.html) |
| [Grpc](https://www.goravel.dev/zh/the-basics/grpc.html) | [Artisan 命令行](https://www.goravel.dev/zh/digging-deeper/artisan-console.html) | [任务调度](https://www.goravel.dev/zh/digging-deeper/task-scheduling.html) | [队列](https://www.goravel.dev/zh/digging-deeper/queues.html) |
| [事件系统](https://www.goravel.dev/zh/digging-deeper/event.html) | [文件存储](https://www.goravel.dev/zh/digging-deeper/filesystem.html) | [邮件](https://www.goravel.dev/zh/digging-deeper/mail.html) | [表单验证](https://www.goravel.dev/zh/the-basics/validation.html) |
| [Mock](https://www.goravel.dev/zh/digging-deeper/mock.html) | [Hash](https://www.goravel.dev/zh/security/hashing.html) | [Crypt](https://www.goravel.dev/zh/security/encryption.html) | [Carbon](https://www.goravel.dev/zh/digging-deeper/helpers.html) |
| [扩展包开发](https://www.goravel.dev/zh/digging-deeper/package-development.html) | [测试](https://www.goravel.dev/zh/testing/getting-started.html) | | |

## 路线图

Expand All @@ -67,6 +67,14 @@ Laravel!
<a href="https://github.com/Marian0" target="_blank"><img src="https://avatars.githubusercontent.com/u/624592?v=4" width="48" height="48"></a>
<a href="https://github.com/ahmed3mar" target="_blank"><img src="https://avatars.githubusercontent.com/u/12982325?v=4" width="48" height="48"></a>
<a href="https://github.com/flc1125" target="_blank"><img src="https://avatars.githubusercontent.com/u/14297703?v=4" width="48" height="48"></a>
<a href="https://github.com/zzpwestlife" target="_blank"><img src="https://avatars.githubusercontent.com/u/12382180?v=4" width="48" height="48"></a>
<a href="https://github.com/juantarrel" target="_blank"><img src="https://avatars.githubusercontent.com/u/7213379?v=4" width="48" height="48"></a>

## 打赏

开源项目的发展离不开您的支持,感谢微信打赏。

<p align="left"><img src="https://www.goravel.dev/reward-wechat.jpg" width="200"></p>

## 群组

Expand Down
9 changes: 6 additions & 3 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,12 @@ func (a *Auth) Logout(ctx http.Context) error {
}

func (a *Auth) makeAuthContext(ctx http.Context, claims *Claims, token string) {
ctx.WithValue(ctxKey, Guards{
a.guard: {claims, token},
})
guards, ok := ctx.Value(ctxKey).(Guards)
if !ok {
guards = make(Guards)
}
guards[a.guard] = &Guard{claims, token}
ctx.WithValue(ctxKey, guards)
}

func (a *Auth) tokenIsDisabled(token string) bool {
Expand Down
86 changes: 79 additions & 7 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/goravel/framework/support/carbon"
)

var guard = "user"
var testUserGuard = "user"

type User struct {
orm.Model
Expand Down Expand Up @@ -107,7 +107,7 @@ func (s *AuthTestSuite) SetupTest() {
s.mockConfig = &configmock.Config{}
s.mockOrm = &ormmock.Orm{}
s.mockDB = &ormmock.Query{}
s.auth = NewAuth(guard, s.mockCache, s.mockConfig, s.mockOrm)
s.auth = NewAuth(testUserGuard, s.mockCache, s.mockConfig, s.mockOrm)
}

func (s *AuthTestSuite) TestLoginUsingID_EmptySecret() {
Expand Down Expand Up @@ -256,7 +256,7 @@ func (s *AuthTestSuite) TestParse_TokenExpired() {

payload, err := s.auth.Parse(ctx, token)
s.Equal(&authcontract.Payload{
Guard: guard,
Guard: testUserGuard,
Key: "1",
ExpireAt: jwt.NewNumericDate(expireAt).Local(),
IssuedAt: jwt.NewNumericDate(issuedAt).Local(),
Expand All @@ -269,7 +269,7 @@ func (s *AuthTestSuite) TestParse_TokenExpired() {
}

func (s *AuthTestSuite) TestParse_InvalidCache() {
auth := NewAuth(guard, nil, s.mockConfig, s.mockOrm)
auth := NewAuth(testUserGuard, nil, s.mockConfig, s.mockOrm)
ctx := Background()
payload, err := auth.Parse(ctx, "1")
s.Nil(payload)
Expand All @@ -288,7 +288,7 @@ func (s *AuthTestSuite) TestParse_Success() {

payload, err := s.auth.Parse(ctx, token)
s.Equal(&authcontract.Payload{
Guard: guard,
Guard: testUserGuard,
Key: "1",
ExpireAt: jwt.NewNumericDate(carbon.Now().AddMinutes(2).ToStdTime()).Local(),
IssuedAt: jwt.NewNumericDate(carbon.Now().ToStdTime()).Local(),
Expand All @@ -311,7 +311,7 @@ func (s *AuthTestSuite) TestParse_SuccessWithPrefix() {

payload, err := s.auth.Parse(ctx, "Bearer "+token)
s.Equal(&authcontract.Payload{
Guard: guard,
Guard: testUserGuard,
Key: "1",
ExpireAt: jwt.NewNumericDate(carbon.Now().AddMinutes(2).ToStdTime()).Local(),
IssuedAt: jwt.NewNumericDate(carbon.Now().ToStdTime()).Local(),
Expand Down Expand Up @@ -464,6 +464,62 @@ func (s *AuthTestSuite) TestUser_Success() {
s.Nil(err)

s.mockConfig.AssertExpectations(s.T())
s.mockCache.AssertExpectations(s.T())
s.mockOrm.AssertExpectations(s.T())
s.mockDB.AssertExpectations(s.T())
}

func (s *AuthTestSuite) TestUser_Success_MultipleParse() {
testAdminGuard := "admin"

s.mockConfig.On("GetString", "jwt.secret").Return("Goravel").Twice()
s.mockConfig.On("GetInt", "jwt.ttl").Return(2).Once()

ctx := Background()
token1, err := s.auth.LoginUsingID(ctx, 1)
s.Nil(err)

s.mockConfig.On("GetString", "jwt.secret").Return("Goravel").Twice()
s.mockConfig.On("GetInt", "jwt.ttl").Return(2).Once()

ctx = Background()
token2, err := s.auth.Guard(testAdminGuard).LoginUsingID(ctx, 2)
s.Nil(err)

s.mockCache.On("GetBool", "jwt:disabled:"+token1, false).Return(false).Once()

payload, err := s.auth.Parse(ctx, token1)
s.Nil(err)
s.NotNil(payload)
s.Equal(testUserGuard, payload.Guard)
s.Equal("1", payload.Key)

s.mockCache.On("GetBool", "jwt:disabled:"+token2, false).Return(false).Once()

payload, err = s.auth.Guard(testAdminGuard).Parse(ctx, token2)
s.Nil(err)
s.NotNil(payload)
s.Equal(testAdminGuard, payload.Guard)
s.Equal("2", payload.Key)

var user1 User
s.mockOrm.On("Query").Return(s.mockDB)
s.mockDB.On("FindOrFail", &user1, clause.Eq{Column: clause.PrimaryColumn, Value: "1"}).Return(nil).Once()

err = s.auth.User(ctx, &user1)
s.Nil(err)

var user2 User
s.mockOrm.On("Query").Return(s.mockDB)
s.mockDB.On("FindOrFail", &user2, clause.Eq{Column: clause.PrimaryColumn, Value: "2"}).Return(nil).Once()

err = s.auth.Guard(testAdminGuard).User(ctx, &user2)
s.Nil(err)

s.mockConfig.AssertExpectations(s.T())
s.mockCache.AssertExpectations(s.T())
s.mockOrm.AssertExpectations(s.T())
s.mockDB.AssertExpectations(s.T())
}

func (s *AuthTestSuite) TestRefresh_NotParse() {
Expand Down Expand Up @@ -541,7 +597,7 @@ func (s *AuthTestSuite) TestRefresh_Success() {
}

func (s *AuthTestSuite) TestLogout_CacheUnsupported() {
s.auth = NewAuth(guard, nil, s.mockConfig, s.mockOrm)
s.auth = NewAuth(testUserGuard, nil, s.mockConfig, s.mockOrm)
s.mockConfig.On("GetString", "jwt.secret").Return("Goravel").Once()
s.mockConfig.On("GetInt", "jwt.ttl").Return(2).Once()

Expand Down Expand Up @@ -644,3 +700,19 @@ func (s *AuthTestSuite) TestLogout_Error_TTL_Is_0() {

s.mockConfig.AssertExpectations(s.T())
}

func (s *AuthTestSuite) TestMakeAuthContext() {
testAdminGuard := "admin"

ctx := Background()
s.auth.makeAuthContext(ctx, nil, "1")
guards, ok := ctx.Value(ctxKey).(Guards)
s.True(ok)
s.Equal(&Guard{nil, "1"}, guards[testUserGuard])

s.auth.Guard(testAdminGuard).(*Auth).makeAuthContext(ctx, nil, "2")
guards, ok = ctx.Value(ctxKey).(Guards)
s.True(ok)
s.Equal(&Guard{nil, "1"}, guards[testUserGuard])
s.Equal(&Guard{nil, "2"}, guards[testAdminGuard])
}
30 changes: 13 additions & 17 deletions config/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,31 @@ type Application struct {
}

func NewApplication(envPath string) *Application {
if !file.Exists(envPath) {
color.Redln("Please create " + envPath + " and initialize it first.")
color.Warnln("Example command: \ncp .env.example .env && go run . artisan key:generate")
os.Exit(0)
}

app := &Application{}
app.vip = viper.New()
app.vip.SetConfigType("env")
app.vip.SetConfigFile(envPath)
app.vip.AutomaticEnv()

if err := app.vip.ReadInConfig(); err != nil {
color.Redln("Invalid Config error: " + err.Error())
os.Exit(0)
}
if file.Exists(envPath) {
app.vip.SetConfigType("env")
app.vip.SetConfigFile(envPath)

app.vip.SetEnvPrefix("goravel")
app.vip.AutomaticEnv()
if err := app.vip.ReadInConfig(); err != nil {
color.Redln("Invalid Config error: " + err.Error())
os.Exit(0)
}
}

appKey := app.Env("APP_KEY")
if support.Env != support.EnvArtisan {
if !support.IsKeyGenerateCommand {
if appKey == nil {
color.Redln("Please initialize APP_KEY first.")
color.Warnln("Example command: \ngo run . artisan key:generate")
color.Println("Create a .env file and run command: go run . artisan key:generate")
color.Println("Or set a system variable: APP_KEY={32-bit number} go run .")
os.Exit(0)
}

if len(appKey.(string)) != 32 {
color.Redln("Invalid APP_KEY, please reset it.")
color.Redln("Invalid APP_KEY, the length must be 32, please reset it.")
color.Warnln("Example command: \ngo run . artisan key:generate")
os.Exit(0)
}
Expand Down
Loading