-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #769 from trheyi/main
Securely update hidden props in the DSL that are only visible to the backend
- Loading branch information
Showing
22 changed files
with
278 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package utils_test | ||
|
||
import ( | ||
"testing" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package utils_test | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package throw | ||
|
||
import ( | ||
"github.com/yaoapp/gou/process" | ||
"github.com/yaoapp/kun/exception" | ||
) | ||
|
||
// Unauthorized throw a unauthorized exception | ||
func Unauthorized(process *process.Process) interface{} { | ||
message := process.ArgsString(0, "Authentication required") | ||
exception.New(message, 401).Throw() | ||
return nil | ||
} | ||
|
||
// Forbidden throw a forbidden exception | ||
func Forbidden(process *process.Process) interface{} { | ||
message := process.ArgsString(0, "Access denied") | ||
exception.New(message, 403).Throw() | ||
return nil | ||
} | ||
|
||
// NotFound throw a not found exception | ||
func NotFound(process *process.Process) interface{} { | ||
message := process.ArgsString(0, "Resource not found") | ||
exception.New(message, 404).Throw() | ||
return nil | ||
} | ||
|
||
// BadRequest throw a bad request exception | ||
func BadRequest(process *process.Process) interface{} { | ||
message := process.ArgsString(0, "Bad Request") | ||
exception.New(message, 400).Throw() | ||
return nil | ||
} | ||
|
||
// InternalError throw a internal error exception | ||
func InternalError(process *process.Process) interface{} { | ||
message := process.ArgsString(0, "Internal Error") | ||
exception.New(message, 500).Throw() | ||
return nil | ||
} | ||
|
||
// Exception throw a exception | ||
func Exception(process *process.Process) interface{} { | ||
process.ValidateArgNums(2) | ||
message := process.ArgsString(0) | ||
code := process.ArgsInt(1) | ||
exception.New(message, code).Throw() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package utils_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/yaoapp/gou/process" | ||
"github.com/yaoapp/yao/utils" | ||
) | ||
|
||
func TestProcessUnauthorized(t *testing.T) { | ||
utils.Init() | ||
proc := process.New("utils.throw.Unauthorized", "Authentication required") | ||
err := proc.Execute() | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "Exception|401: Authentication required", err.Error()) | ||
} | ||
|
||
func TestProcessForbidden(t *testing.T) { | ||
utils.Init() | ||
proc := process.New("utils.throw.Forbidden", "Access denied") | ||
err := proc.Execute() | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "Exception|403: Access denied", err.Error()) | ||
} | ||
|
||
func TestProcessNotFound(t *testing.T) { | ||
utils.Init() | ||
proc := process.New("utils.throw.NotFound", "Resource not found") | ||
err := proc.Execute() | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "Exception|404: Resource not found", err.Error()) | ||
} | ||
|
||
func TestProcessBadRequest(t *testing.T) { | ||
utils.Init() | ||
proc := process.New("utils.throw.BadRequest", "Bad Request") | ||
err := proc.Execute() | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "Exception|400: Bad Request", err.Error()) | ||
} | ||
|
||
func TestProcessInternalError(t *testing.T) { | ||
utils.Init() | ||
proc := process.New("utils.throw.InternalError", "Internal Error") | ||
err := proc.Execute() | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "Exception|500: Internal Error", err.Error()) | ||
} | ||
|
||
func TestProcessException(t *testing.T) { | ||
utils.Init() | ||
proc := process.New("utils.throw.Exception", "I'm a teapot", 418) | ||
err := proc.Execute() | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "Exception|418: I'm a teapot", err.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package utils_test | ||
|
||
import ( | ||
"testing" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.