-
Notifications
You must be signed in to change notification settings - Fork 16
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
Implementing Galadriel Server Management Handlers API #150
Changes from 11 commits
bfdfcc4
cbdaf26
c55c71b
664cb58
d02e836
a55e8fa
a7edd5d
c621801
4b49fcc
5f3dcbd
9bc7b3a
46ca412
02de6e6
990cd61
85ce235
63306ec
2b5d958
38449f0
21b679b
d9b7d39
7eafbe5
f085b5d
b60cec3
4da954f
b92ffcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,21 +34,22 @@ func Setup() *HTTPSetup { | |
func TestWriteResponse(t *testing.T) { | ||
t.Run("Error when nil body is passed", func(t *testing.T) { | ||
setup := Setup() | ||
err := WriteResponse(setup.EchoContext, nil) | ||
err := WriteResponse(setup.EchoContext, 0, nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||
assert.EqualError(t, err, "body is required") | ||
assert.Empty(t, setup.Recorder.Body) | ||
}) | ||
|
||
t.Run("No error when an empty body is passed", func(t *testing.T) { | ||
setup := Setup() | ||
err := WriteResponse(setup.EchoContext, TestBody{}) | ||
err := WriteResponse(setup.EchoContext, http.StatusOK, TestBody{}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, setup.Recorder.Code) | ||
}) | ||
|
||
t.Run("Ensuring that the body is being full filled with the entity", func(t *testing.T) { | ||
expectedResponseBody := TestBody{Name: "teste"} | ||
setup := Setup() | ||
err := WriteResponse(setup.EchoContext, expectedResponseBody) | ||
err := WriteResponse(setup.EchoContext, http.StatusOK, expectedResponseBody) | ||
assert.NoError(t, err) | ||
|
||
responseBody := TestBody{} | ||
|
@@ -60,10 +61,10 @@ func TestWriteResponse(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestBodylessResponse(t *testing.T) { | ||
func TestBodilessResponse(t *testing.T) { | ||
t.Run("Ensuring that the body is empty", func(t *testing.T) { | ||
setup := Setup() | ||
err := BodylessResponse(setup.EchoContext) | ||
err := BodilessResponse(setup.EchoContext, http.StatusOK) | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, err) | ||
|
@@ -75,7 +76,7 @@ func TestBodylessResponse(t *testing.T) { | |
func TestFromBody(t *testing.T) { | ||
t.Run("Ensuring that the body is empty", func(t *testing.T) { | ||
setup := Setup() | ||
err := BodylessResponse(setup.EchoContext) | ||
err := BodilessResponse(setup.EchoContext, http.StatusOK) | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,8 @@ func SetupMiddleware() *AuthNTestSetup { | |
} | ||
} | ||
|
||
func SetupToken(t *testing.T, ds datastore.Datastore, token string, tdID uuid.UUID) *entity.JoinToken { | ||
td, err := spiffeid.TrustDomainFromString(testTrustDomain) | ||
func SetupToken(t *testing.T, ds datastore.Datastore, tdID uuid.UUID, token, tdName string) *entity.JoinToken { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function doesn't exist anymore. |
||
td, err := spiffeid.TrustDomainFromString(tdName) | ||
assert.NoError(t, err) | ||
|
||
jt := &entity.JoinToken{ | ||
|
@@ -67,7 +67,7 @@ func TestAuthenticate(t *testing.T) { | |
t.Run("Authorized tokens must be able to pass authn verification", func(t *testing.T) { | ||
authnSetup := SetupMiddleware() | ||
token := GenerateSecureToken(10) | ||
SetupToken(t, authnSetup.FakeDatabase, token, uuid.New()) | ||
SetupToken(t, authnSetup.FakeDatabase, uuid.New(), token, td1) | ||
|
||
authorized, err := authnSetup.Middleware.Authenticate(token, authnSetup.EchoCtx) | ||
assert.NoError(t, err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package endpoints | ||
|
||
const ( | ||
testTrustDomain = "test.com" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need to create a separate file for constants used in tests. |
||
td1 = "test1.com" | ||
td2 = "test2.com" | ||
td3 = "test3.com" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why add this parameter that is not used?
Name suggestions for this function:
NoContentResponse
orEmptyResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misstype