Skip to content

Commit b0b24e6

Browse files
authored
Merge pull request step-security#2570 from vamshi-stepsecurity/refactor/dependabot/vk/support-cool-down
cooldown in additive
2 parents 0b58477 + 2f10ead commit b0b24e6

4 files changed

Lines changed: 81 additions & 1 deletion

File tree

remediation/dependabot/dependabotconfig.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ func UpdateDependabotConfig(dependabotConfig string) (*UpdateDependabotConfigRes
170170
Directory: Update.Directory,
171171
Schedule: dependabot.Schedule{Interval: Update.Interval},
172172
},
173-
Groups: Update.Groups,
173+
Groups: Update.Groups,
174+
CoolDown: Update.CoolDown,
174175
}
175176
items := []ExtendedUpdate{item}
176177
addedItem, err := yaml.Marshal(items)

remediation/dependabot/dependabotconfig_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,66 @@ func TestGroups(t *testing.T) {
211211
}
212212
}
213213

214+
func TestAdditiveCoolDown(t *testing.T) {
215+
const inputDirectory = "../../testfiles/dependabotfiles/input"
216+
const outputDirectory = "../../testfiles/dependabotfiles/output"
217+
218+
tests := []struct {
219+
inputFileName string
220+
outputFileName string
221+
ecosystems []Ecosystem
222+
isChanged bool
223+
}{
224+
{
225+
// Additive — new ecosystem added with CoolDown; CoolDown must appear in output.
226+
inputFileName: "additive-new-with-cooldown.yml",
227+
outputFileName: "additive-new-with-cooldown.yml",
228+
ecosystems: []Ecosystem{
229+
{
230+
PackageEcosystem: "npm",
231+
Directory: "/",
232+
Interval: "weekly",
233+
CoolDown: &CoolDown{DefaultDays: 5},
234+
},
235+
},
236+
isChanged: true,
237+
},
238+
}
239+
240+
for _, test := range tests {
241+
input, err := ioutil.ReadFile(path.Join(inputDirectory, test.inputFileName))
242+
if err != nil {
243+
log.Fatal(err)
244+
}
245+
req := UpdateDependabotConfigRequest{
246+
Content: string(input),
247+
Ecosystems: test.ecosystems,
248+
Subtractive: false,
249+
}
250+
inputJSON, err := json.Marshal(req)
251+
if err != nil {
252+
log.Fatal(err)
253+
}
254+
255+
output, err := UpdateDependabotConfig(string(inputJSON))
256+
if err != nil {
257+
t.Fatalf("Error not expected: %s", err)
258+
}
259+
260+
expectedOutput, err := ioutil.ReadFile(path.Join(outputDirectory, test.outputFileName))
261+
if err != nil {
262+
log.Fatal(err)
263+
}
264+
265+
if string(expectedOutput) != output.FinalOutput {
266+
t.Errorf("test failed %s did not match expected output\n%s", test.outputFileName, output.FinalOutput)
267+
}
268+
if output.IsChanged != test.isChanged {
269+
t.Errorf("test failed %s did not match IsChanged, Expected: %v Got: %v", test.outputFileName, test.isChanged, output.IsChanged)
270+
}
271+
}
272+
}
273+
214274
func TestUpdateSubtractiveFields(t *testing.T) {
215275
const inputDirectory = "../../testfiles/dependabotfiles/input"
216276
const outputDirectory = "../../testfiles/dependabotfiles/output"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
8+
- package-ecosystem: npm
9+
directory: /
10+
schedule:
11+
interval: weekly
12+
cooldown:
13+
default-days: 5

0 commit comments

Comments
 (0)