Skip to content

Commit 3b9db07

Browse files
committed
fix codeql and bump code coverage
- update codeql comment/report when there are multiple pushes to the same PR - improve test coverage
1 parent b8273b4 commit 3b9db07

File tree

6 files changed

+71
-40
lines changed

6 files changed

+71
-40
lines changed

.github/workflows/codeql-analysis.yml

+47-31
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,82 @@
1-
name: codeql-analysis
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
214
on:
315
push:
4-
branches: [main]
16+
branches: [ "main" ]
517
pull_request:
618
# The branches below must be a subset of the branches above
7-
branches: [main]
19+
branches: [ "main" ]
820
schedule:
9-
- cron: '0 20 * * 2'
21+
- cron: '42 17 * * 5'
1022

1123
jobs:
1224
analyze:
1325
name: Analyze
14-
runs-on: ubuntu-latest
26+
# Runner size impacts CodeQL analysis time. To learn more, please see:
27+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
28+
# - https://gh.io/supported-runners-and-hardware-resources
29+
# - https://gh.io/using-larger-runners
30+
# Consider using larger runners for possible analysis time improvements.
31+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
32+
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
33+
permissions:
34+
actions: read
35+
contents: read
36+
security-events: write
1537

1638
strategy:
1739
fail-fast: false
1840
matrix:
19-
# Override automatic language detection by changing the below list
20-
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
21-
language: ['go']
22-
# Learn more...
23-
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
41+
language: [ 'go' ]
42+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
43+
# Use only 'java' to analyze code written in Java, Kotlin or both
44+
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
45+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
2446

2547
steps:
2648
- name: Checkout repository
27-
uses: actions/checkout@v2
28-
with:
29-
# We must fetch at least the immediate parents so that if this is
30-
# a pull request then we can checkout the head.
31-
fetch-depth: 2
32-
33-
# If this run was triggered by a pull request event, then checkout
34-
# the head of the pull request instead of the merge commit.
35-
# Note: no longer recommended!
36-
# - run: git checkout HEAD^2
37-
# if: ${{ github.event_name == 'pull_request' }}
49+
uses: actions/checkout@v3
3850

3951
# Initializes the CodeQL tools for scanning.
4052
- name: Initialize CodeQL
4153
uses: github/codeql-action/init@v2
4254
with:
4355
languages: ${{ matrix.language }}
4456
# If you wish to specify custom queries, you can do so here or in a config file.
45-
# By default, queries listed here will override any specified in a config file.
57+
# By default, queries listed here will override any specified in a config file.
4658
# Prefix the list here with "+" to use these queries and those in the config file.
47-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
4859

49-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
60+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
61+
# queries: security-extended,security-and-quality
62+
63+
64+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
5065
# If this step fails, then you should remove it and run the build manually (see below)
5166
- name: Autobuild
5267
uses: github/codeql-action/autobuild@v2
5368

5469
# ℹ️ Command-line programs to run using the OS shell.
55-
# 📚 https://git.io/JvXDl
70+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
5671

57-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
58-
# and modify them (or add more) to build your code if your project
59-
# uses a compiled language
72+
# If the Autobuild fails above, remove it and uncomment the following three lines.
73+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
6074

61-
#- run: |
62-
# make bootstrap
63-
# make release
75+
# - run: |
76+
# echo "Run, Build Application using script"
77+
# ./location_of_script_within_repo/buildscript.sh
6478

6579
- name: Perform CodeQL Analysis
6680
uses: github/codeql-action/analyze@v2
81+
with:
82+
category: "/language:${{matrix.language}}"

sso/cache_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ func (suite *CacheTestSuite) TestGetAllTags() {
393393
cache := suite.cache.GetSSO()
394394

395395
tl := cache.Roles.GetAllTags()
396-
assert.Equal(t, 9, len(*tl))
396+
assert.Equal(t, 10, len(*tl))
397397
tl = suite.cache.GetAllTagsSelect()
398-
assert.Equal(t, 9, len(*tl))
398+
assert.Equal(t, 10, len(*tl))
399399
}
400400

401401
func (suite *CacheTestSuite) TestGetRoleTags() {

sso/roles.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ func (r *Roles) GetRole(accountId int64, roleName string) (*AWSRoleFlat, error)
134134
}
135135

136136
for thisRoleName, role := range account.Roles {
137-
idStr, err := utils.AccountIdToString(accountId)
138-
if err != nil {
139-
return &AWSRoleFlat{}, err
140-
}
137+
idStr, _ := utils.AccountIdToString(accountId)
141138
if thisRoleName == roleName {
142139
flat := AWSRoleFlat{
143140
AccountId: accountId,

sso/roles_test.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,6 @@ func (suite *CacheRolesTestSuite) TestGetRole() {
162162
_, err := roles.GetRole(58234615182, "AWSAdministratorAccess")
163163
assert.Error(t, err)
164164

165-
_, err = roles.GetRole(234234234324234234, "AWSAdministratorAccess")
166-
assert.Error(t, err)
167-
168165
r, err := roles.GetRole(25823461518, "AWSAdministratorAccess")
169166
assert.NoError(t, err)
170167
assert.Equal(t, int64(25823461518), r.AccountId)
@@ -175,6 +172,10 @@ func (suite *CacheRolesTestSuite) TestGetRole() {
175172
p, err := r.ProfileName(suite.settings)
176173
assert.NoError(t, err)
177174
assert.Equal(t, "OurCompany Control Tower Playground/AWSAdministratorAccess", p)
175+
176+
r, err = roles.GetRole(707513610766, "AWSPowerUserAccess")
177+
assert.NoError(t, err)
178+
assert.Equal(t, "arn:aws:iam::707513610766:role/AWSReadOnlyAccess", r.Via)
178179
}
179180

180181
func (suite *CacheRolesTestSuite) TestProfileName() {
@@ -362,6 +363,10 @@ func TestStringsJoin(t *testing.T) {
362363
assert.Equal(t, "a.b.c", stringsJoin(".", "a", "b", "c"))
363364
}
364365

366+
func TestAccountIdToStr(t *testing.T) {
367+
assert.Equal(t, "000000555555", accountIdToStr(555555))
368+
}
369+
365370
func TestAWSRoleFlatHasPrefix(t *testing.T) {
366371
f := &AWSRoleFlat{
367372
Id: 10,
@@ -475,3 +480,14 @@ func (suite *CacheRolesTestSuite) TestCheckProfiles() {
475480
err = r.checkProfiles(&badSettings)
476481
assert.Error(t, err)
477482
}
483+
484+
func (suite *CacheRolesTestSuite) TestGetRoleChain() {
485+
t := suite.T()
486+
487+
roles := suite.cache.SSO[suite.cache.ssoName].Roles
488+
flat := roles.GetRoleChain(707513610766, "AWSPowerUserAccess")
489+
assert.Equal(t, 2, len(flat))
490+
491+
assert.Equal(t, "arn:aws:iam::707513610766:role/AWSReadOnlyAccess", flat[0].Arn)
492+
assert.Equal(t, "arn:aws:iam::707513610766:role/AWSPowerUserAccess", flat[1].Arn)
493+
}

sso/testdata/cache.json

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
},
213213
"AWSPowerUserAccess": {
214214
"Arn": "arn:aws:iam::707513610766:role/AWSPowerUserAccess",
215+
"Via": "arn:aws:iam::707513610766:role/AWSReadOnlyAccess",
215216
"Tags": {
216217
"AccountAlias": "control-tower-dev-sub1-aws",
217218
"AccountID": "707513610766",

sso/testdata/roles_tests.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Valid1:
2626
Profile: FunnyMan
2727
Foobar2:
2828
Profile: FunnyMan2
29+
Via: arn:aws:iam::0000001:role/FunnyMan
2930

3031
Valid2:
3132
Accounts:

0 commit comments

Comments
 (0)