-
Notifications
You must be signed in to change notification settings - Fork 3
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 #91 from padok-team/oussama/feat-checks
Oussama/feat checks
- Loading branch information
Showing
16 changed files
with
620 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cognito | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider" | ||
"github.com/padok-team/yatas/plugins/commons" | ||
) | ||
|
||
func CheckIfCognitoSelfRegistration(checkConfig commons.CheckConfig, cognitoUserPools []cognitoidentityprovider.DescribeUserPoolOutput, testName string) { | ||
var check commons.Check | ||
check.InitCheck("Cognito allows self-registration", "Check if Cognito allows self-registration", testName, []string{"Security", "Good Practice"}) | ||
for _, c := range cognitoUserPools { | ||
if !c.UserPool.AdminCreateUserConfig.AllowAdminCreateUserOnly { | ||
Message := "Cognito allows self-registration on " + *c.UserPool.Name | ||
result := commons.Result{Status: "FAIL", Message: Message, ResourceID: *c.UserPool.Arn} | ||
check.AddResult(result) | ||
} else { | ||
Message := "Cognito does not allow self-registration on " + *c.UserPool.Name | ||
result := commons.Result{Status: "OK", Message: Message, ResourceID: *c.UserPool.Arn} | ||
check.AddResult(result) | ||
} | ||
} | ||
checkConfig.Queue <- check | ||
} |
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,99 @@ | ||
package cognito | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider" | ||
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/types" | ||
"github.com/padok-team/yatas/plugins/commons" | ||
) | ||
|
||
func TestCheckIfCognitoSelfRegistration(t *testing.T) { | ||
type args struct { | ||
checkConfig commons.CheckConfig | ||
cognitoUserPools []cognitoidentityprovider.DescribeUserPoolOutput | ||
testName string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
name: "TestCheckIfCognitoSelfRegistration", | ||
args: args{ | ||
checkConfig: commons.CheckConfig{Queue: make(chan commons.Check, 1), Wg: &sync.WaitGroup{}}, | ||
cognitoUserPools: []cognitoidentityprovider.DescribeUserPoolOutput{ | ||
{ | ||
UserPool: &types.UserPoolType{ | ||
Name: aws.String("test"), | ||
Arn: aws.String("arn:aws:cognito-idp:us-east-1:123456789012:userpool/us-east-1_test"), | ||
AdminCreateUserConfig: &types.AdminCreateUserConfigType{AllowAdminCreateUserOnly: true}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
CheckIfCognitoSelfRegistration(tt.args.checkConfig, tt.args.cognitoUserPools, tt.args.testName) | ||
tt.args.checkConfig.Wg.Add(1) | ||
go func() { | ||
for check := range tt.args.checkConfig.Queue { | ||
if check.Status != "OK" { | ||
t.Errorf("CheckIfCognitoSelfRegistration() = %v, want %v", check.Status, "OK") | ||
} | ||
tt.args.checkConfig.Wg.Done() | ||
} | ||
}() | ||
tt.args.checkConfig.Wg.Wait() | ||
}) | ||
} | ||
} | ||
|
||
func TestCheckIfCognitoSelfRegistrationFail(t *testing.T) { | ||
type args struct { | ||
checkConfig commons.CheckConfig | ||
cognitoUserPools []cognitoidentityprovider.DescribeUserPoolOutput | ||
testName string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
name: "TestCheckIfCognitoSelfRegistration", | ||
args: args{ | ||
checkConfig: commons.CheckConfig{Queue: make(chan commons.Check, 1), Wg: &sync.WaitGroup{}}, | ||
cognitoUserPools: []cognitoidentityprovider.DescribeUserPoolOutput{ | ||
{ | ||
UserPool: &types.UserPoolType{ | ||
Name: aws.String("test"), | ||
Arn: aws.String("arn:aws:cognito-idp:us-east-1:123456789012:userpool/us-east-1_test"), | ||
AdminCreateUserConfig: &types.AdminCreateUserConfigType{AllowAdminCreateUserOnly: false}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
CheckIfCognitoSelfRegistration(tt.args.checkConfig, tt.args.cognitoUserPools, tt.args.testName) | ||
tt.args.checkConfig.Wg.Add(1) | ||
go func() { | ||
for check := range tt.args.checkConfig.Queue { | ||
if check.Status != "FAIL" { | ||
t.Errorf("CheckIfCognitoSelfRegistration() = %v, want %v", check.Status, "FAIL") | ||
} | ||
tt.args.checkConfig.Wg.Done() | ||
} | ||
}() | ||
tt.args.checkConfig.Wg.Wait() | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package cognito | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/cognitoidentity" | ||
"github.com/padok-team/yatas/plugins/commons" | ||
) | ||
|
||
func TestCheckIfCognitoAllowsUnauthenticated(t *testing.T) { | ||
type args struct { | ||
checkConfig commons.CheckConfig | ||
cognitoPools []cognitoidentity.DescribeIdentityPoolOutput | ||
testName string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
name: "TestCheckIfCognitoAllowsUnauthenticated", | ||
args: args{ | ||
checkConfig: commons.CheckConfig{Queue: make(chan commons.Check, 1), Wg: &sync.WaitGroup{}}, | ||
cognitoPools: []cognitoidentity.DescribeIdentityPoolOutput{ | ||
{ | ||
IdentityPoolName: aws.String("test"), | ||
IdentityPoolId: aws.String("us-east-1:cb21213c-a931-11ed-afa1-0242ac120002"), | ||
AllowUnauthenticatedIdentities: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
CheckIfCognitoAllowsUnauthenticated(tt.args.checkConfig, tt.args.cognitoPools, tt.args.testName) | ||
tt.args.checkConfig.Wg.Add(1) | ||
go func() { | ||
for check := range tt.args.checkConfig.Queue { | ||
if check.Status != "OK" { | ||
t.Errorf("CheckIfCognitoAllowsUnauthenticated() = %v, want %v", check.Status, "OK") | ||
} | ||
tt.args.checkConfig.Wg.Done() | ||
} | ||
}() | ||
tt.args.checkConfig.Wg.Wait() | ||
}) | ||
} | ||
} | ||
|
||
func TestCheckIfCognitoAllowsUnauthenticatedFail(t *testing.T) { | ||
type args struct { | ||
checkConfig commons.CheckConfig | ||
cognitoPools []cognitoidentity.DescribeIdentityPoolOutput | ||
testName string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
name: "TestCheckIfCognitoAllowsUnauthenticated", | ||
args: args{ | ||
checkConfig: commons.CheckConfig{Queue: make(chan commons.Check, 1), Wg: &sync.WaitGroup{}}, | ||
cognitoPools: []cognitoidentity.DescribeIdentityPoolOutput{ | ||
{ | ||
IdentityPoolName: aws.String("test"), | ||
IdentityPoolId: aws.String("us-east-1:cb21213c-a931-11ed-afa1-0242ac120002"), | ||
AllowUnauthenticatedIdentities: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
CheckIfCognitoAllowsUnauthenticated(tt.args.checkConfig, tt.args.cognitoPools, tt.args.testName) | ||
tt.args.checkConfig.Wg.Add(1) | ||
go func() { | ||
for check := range tt.args.checkConfig.Queue { | ||
if check.Status != "FAIL" { | ||
t.Errorf("CheckIfCognitoAllowsUnauthenticated() = %v, want %v", check.Status, "FAIL") | ||
} | ||
tt.args.checkConfig.Wg.Done() | ||
} | ||
}() | ||
tt.args.checkConfig.Wg.Wait() | ||
}) | ||
} | ||
} |
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.