Skip to content

Commit

Permalink
[Dembo] Refactor security middleware authorization to extract job met…
Browse files Browse the repository at this point in the history
…adata
  • Loading branch information
walbertus committed Aug 30, 2019
1 parent 41538e0 commit ecaac86
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions internal/app/service/security/middleware/authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type authorizationContext struct {
requestHandler func(http.Handler) http.Handler
metadataRepository *repository.MockMetadataRepository
securityService *service.SecurityServiceMock
jobMetadata *metadata.Metadata
}

func (context *authorizationContext) setUp(t *testing.T) {
Expand All @@ -35,6 +36,15 @@ func (context *authorizationContext) setUp(t *testing.T) {
context.authorizationMiddleware.metadataRepository = context.metadataRepository
context.securityService = &service.SecurityServiceMock{}
context.authorizationMiddleware.service = context.securityService
context.jobMetadata = &metadata.Metadata{
Name: "a-job",
Description: "jobMetadata of a job",
ImageName: "ubuntu-18.04",
AuthorizedGroups: []string{"system", "proctor_maintainer"},
Author: "systeam team",
Contributors: "proctor team",
Organization: "GoJek",
}
}

func (context *authorizationContext) tearDown() {
Expand All @@ -56,15 +66,7 @@ func TestAuthorizationMiddleware_MiddlewareFuncSuccess(t *testing.T) {
requestBody := map[string]string{}
requestBody["name"] = "a-job"
body, _ := json.Marshal(requestBody)
jobMetadata := &metadata.Metadata{
Name: "a-job",
Description: "jobMetadata of a job",
ImageName: "ubuntu-18.04",
AuthorizedGroups: []string{"system", "proctor_maintainer"},
Author: "systeam team",
Contributors: "proctor team",
Organization: "GoJek",
}
jobMetadata := ctx.jobMetadata
userDetail := &auth.UserDetail{
Name: "William Dembo",
Email: "email@gmail.com",
Expand Down Expand Up @@ -151,15 +153,7 @@ func TestAuthorizationMiddleware_MiddlewareFuncWithoutUserDetail(t *testing.T) {
requestBody := map[string]string{}
requestBody["name"] = "a-job"
body, _ := json.Marshal(requestBody)
jobMetadata := &metadata.Metadata{
Name: "a-job",
Description: "jobMetadata of a job",
ImageName: "ubuntu-18.04",
AuthorizedGroups: []string{"system", "proctor_maintainer"},
Author: "systeam team",
Contributors: "proctor team",
Organization: "GoJek",
}
jobMetadata := ctx.jobMetadata

response := httptest.NewRecorder()
request := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(body))
Expand All @@ -186,15 +180,7 @@ func TestAuthorizationMiddleware_MiddlewareFuncFailed(t *testing.T) {
requestBody := map[string]string{}
requestBody["name"] = "a-job"
body, _ := json.Marshal(requestBody)
jobMetadata := &metadata.Metadata{
Name: "a-job",
Description: "jobMetadata of a job",
ImageName: "ubuntu-18.04",
AuthorizedGroups: []string{"system", "proctor_maintainer"},
Author: "systeam team",
Contributors: "proctor team",
Organization: "GoJek",
}
jobMetadata := ctx.jobMetadata
userDetail := &auth.UserDetail{
Name: "William Dembo",
Email: "email@gmail.com",
Expand Down

0 comments on commit ecaac86

Please sign in to comment.