Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djelusic committed Feb 28, 2022
1 parent 36207f2 commit 150dbc9
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 18 deletions.
11 changes: 11 additions & 0 deletions cli/controller/testdata/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ Resources:
- logs:DeleteLogDelivery
Resource:
- "*"
- Effect: Allow
Action:
- ssm:PutParameter
- ssm:AddTagsToResource
- ssm:ListTagsForResource
- ssm:GetParameter
- ssm:GetParameters
- ssm:DescribeParameters
- ssm:DeleteParameter
Resource:
- "*"
MantilSetupLambda:
Type: AWS::Lambda::Function
Properties:
Expand Down
16 changes: 8 additions & 8 deletions domain/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,32 @@ func TestReadUserClaims(t *testing.T) {
}

publicKey, privateKey, err := token.KeyPair()
require.NoError(t, err)

headers := make(map[string]string)

_, err = ReadAccessToken(headers)
_, err = ReadAccessToken(headers, "")
require.Error(t, err)
require.Contains(t, err.Error(), "token not found")

token, err := token.JWT(privateKey, c, 7*24*time.Hour)
require.NoError(t, err)

headers[strings.ToLower(AccessTokenHeader)] = token
_, err = ReadAccessToken(headers)
_, err = ReadAccessToken(headers, "")
require.Error(t, err)
require.Contains(t, err.Error(), "key not found")
require.Contains(t, err.Error(), "invalid key")

// happy path
t.Setenv(EnvPublicKey, publicKey)
c2, err := ReadAccessToken(headers)
c2, err := ReadAccessToken(headers, publicKey)
require.NoError(t, err)
require.Equal(t, &c, c2)

headers[strings.ToLower(AccessTokenHeader)] = token
c2, err = ReadAccessToken(headers)
c2, err = ReadAccessToken(headers, publicKey)
require.NoError(t, err)
require.Equal(t, &c, c2)

headers[AccessTokenHeader] = "foo"
_, err = ReadAccessToken(headers)
_, err = ReadAccessToken(headers, publicKey)
require.Error(t, err)
}
5 changes: 4 additions & 1 deletion node/api/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ func TestTerraformRender(t *testing.T) {
Region: "aws-region",
ResourceSuffix: "abcdef",
AuthEnv: map[string]string{
"publicKey": "key",
"publicKey": "public_key",
},
ResourceTags: map[string]string{
"tag1": "value1",
"tag2": "value2",
},
NamingTemplate: "mantil-%s",
PublicKey: "public_key",
PrivateKey: "private_key",
GithubOrg: "github_org",
}
tf, err := terraform.Setup(data)
require.NoError(t, err)
Expand Down
35 changes: 31 additions & 4 deletions node/api/setup/testdata/create.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ locals {
tag1 = "value1"
tag2 = "value2"
}
ssm_prefix = "/mantil-node-abcdef"
auth_env = {
publicKey = "public_key"
}
}

terraform {
Expand Down Expand Up @@ -35,6 +39,7 @@ module "functions" {
region = local.aws_region
cli_role_arn = module.cli_role.arn
naming_template = "mantil-%s"
auth_env = local.auth_env
}


Expand All @@ -58,17 +63,39 @@ module "api" {
route : "/${f.name}"
uri : f.invoke_arn,
lambda_name : f.arn,
enable_auth : true,
enable_auth : f.name != "auth" ? true : false,
}
]
authorizer = {
authorization_header = "Authorization"
env = {
publicKey = "key"
}
env = local.auth_env
}
}

module "params" {
source = "../../modules/params"
path_prefix = local.ssm_prefix
params = [
{
name : "public_key"
value : "public_key"
},
{
name : "private_key"
value : "private_key"
secure : true
},
{
name: "github_org"
value : "github_org"
},
{
name: "github_user"
value : ""
}
]
}

# expose aws region and profile for use in shell scripts
output "aws_region" {
value = local.aws_region
Expand Down
5 changes: 4 additions & 1 deletion node/terraform/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ func TestRenderSetup(t *testing.T) {
Region: "aws-region",
ResourceSuffix: "abcdef",
AuthEnv: map[string]string{
"publicKey": "key",
"publicKey": "public_key",
},
ResourceTags: map[string]string{
"tag1": "value1",
"tag2": "value2",
},
NamingTemplate: "prefix-%s-suffix",
PublicKey: "public_key",
PrivateKey: "private_key",
GithubOrg: "github_org",
}
tf, err := renderSetup(data)
require.NoError(t, err)
Expand Down
35 changes: 31 additions & 4 deletions node/terraform/testdata/setup.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ locals {
tag1 = "value1"
tag2 = "value2"
}
ssm_prefix = "/mantil-node-abcdef"
auth_env = {
publicKey = "public_key"
}
}

terraform {
Expand Down Expand Up @@ -35,6 +39,7 @@ module "functions" {
region = local.aws_region
cli_role_arn = module.cli_role.arn
naming_template = "prefix-%s-suffix"
auth_env = local.auth_env
}


Expand All @@ -58,17 +63,39 @@ module "api" {
route : "/${f.name}"
uri : f.invoke_arn,
lambda_name : f.arn,
enable_auth : true,
enable_auth : f.name != "auth" ? true : false,
}
]
authorizer = {
authorization_header = "Authorization"
env = {
publicKey = "key"
}
env = local.auth_env
}
}

module "params" {
source = "../../modules/params"
path_prefix = local.ssm_prefix
params = [
{
name : "public_key"
value : "public_key"
},
{
name : "private_key"
value : "private_key"
secure : true
},
{
name: "github_org"
value : "github_org"
},
{
name: "github_user"
value : ""
}
]
}

# expose aws region and profile for use in shell scripts
output "aws_region" {
value = local.aws_region
Expand Down

0 comments on commit 150dbc9

Please sign in to comment.