@@ -4,8 +4,10 @@ import (
4
4
"io/ioutil"
5
5
"os"
6
6
"path/filepath"
7
+ "strings"
7
8
"time"
8
9
10
+ "github.com/mcuadros/ofelia/core"
9
11
. "gopkg.in/check.v1"
10
12
)
11
13
@@ -15,6 +17,31 @@ type SuiteSave struct {
15
17
16
18
var _ = Suite (& SuiteSave {})
17
19
20
+ func (s * SuiteSave ) SetUpTest (c * C ) {
21
+ job := & TestJobConfig {
22
+ TestJob : TestJob {
23
+ BareJob : core.BareJob {
24
+ Name : "test-job-save" ,
25
+ },
26
+ },
27
+ MailConfig : MailConfig {
28
+ SMTPHost : "test-host" ,
29
+ SMTPPassword : "secret-password" ,
30
+ SMTPUser : "secret-user" ,
31
+ },
32
+ SlackConfig : SlackConfig {
33
+ SlackWebhook : "secret-url" ,
34
+ },
35
+ }
36
+
37
+ s .job = & job .TestJob
38
+
39
+ sh := core .NewScheduler (& TestLogger {})
40
+ e := core .NewExecution ()
41
+
42
+ s .ctx = core .NewContext (sh , job , e )
43
+ }
44
+
18
45
func (s * SuiteSave ) TestNewSlackEmpty (c * C ) {
19
46
c .Assert (NewSave (& SaveConfig {}), IsNil )
20
47
}
@@ -58,3 +85,41 @@ func (s *SuiteSave) TestRunSuccessOnError(c *C) {
58
85
_ , err = os .Stat (filepath .Join (dir , "00010101_000000_foo.json" ))
59
86
c .Assert (err , Not (IsNil ))
60
87
}
88
+
89
+ func (s * SuiteSave ) TestSensitiveData (c * C ) {
90
+ dir , err := ioutil .TempDir ("/tmp" , "save" )
91
+ c .Assert (err , IsNil )
92
+
93
+ s .ctx .Start ()
94
+ s .ctx .Stop (nil )
95
+
96
+ s .job .Name = "job-with-sensitive-data"
97
+ s .ctx .Execution .Date = time.Time {}
98
+
99
+ m := NewSave (& SaveConfig {SaveFolder : dir })
100
+ c .Assert (m .Run (s .ctx ), IsNil )
101
+
102
+ expectedFileName := "00010101_000000_job-with-sensitive-data"
103
+ _ , err = os .Stat (filepath .Join (dir , expectedFileName + ".json" ))
104
+ c .Assert (err , IsNil )
105
+
106
+ _ , err = os .Stat (filepath .Join (dir , expectedFileName + ".stdout.log" ))
107
+ c .Assert (err , IsNil )
108
+
109
+ _ , err = os .Stat (filepath .Join (dir , expectedFileName + ".stderr.log" ))
110
+ c .Assert (err , IsNil )
111
+
112
+ files , err := os .ReadDir (dir )
113
+ c .Assert (err , IsNil )
114
+ c .Assert (files , HasLen , 3 )
115
+
116
+ for _ , file := range files {
117
+ b , err := os .ReadFile (filepath .Join (dir , file .Name ()))
118
+ c .Assert (err , IsNil )
119
+
120
+ if strings .Contains (string (b ), "secret" ) {
121
+ c .Log (string (b ))
122
+ c .Errorf ("found secret string in %q" , file .Name ())
123
+ }
124
+ }
125
+ }
0 commit comments