14
14
JobTemplateNotification ,
15
15
)
16
16
from onefuzztypes .models import (
17
+ ADOTemplate ,
18
+ GithubAuth ,
19
+ GithubIssueTemplate ,
17
20
JobConfig ,
18
21
Notification ,
19
22
NotificationConfig ,
27
30
from __app__ .onefuzzlib .orm import hide_secrets
28
31
29
32
33
+ def hider (secret_data : SecretData ) -> SecretData :
34
+ if not isinstance (secret_data .secret , SecretAddress ):
35
+ secret_data .secret = SecretAddress (url = "blah blah" )
36
+ return secret_data
37
+
38
+
30
39
class TestSecret (unittest .TestCase ):
31
40
def test_hide (self ) -> None :
32
- def hider (secret_data : SecretData ) -> SecretData :
33
- if not isinstance (secret_data .secret , SecretAddress ):
34
- secret_data .secret = SecretAddress (url = "blah blah" )
35
- return secret_data
36
-
37
41
notification = Notification (
38
42
container = Container ("data" ),
39
43
config = TeamsTemplate (url = SecretData (secret = "http://test" )),
@@ -47,11 +51,6 @@ def hider(secret_data: SecretData) -> SecretData:
47
51
self .fail (f"Invalid config type { type (notification .config )} " )
48
52
49
53
def test_hide_nested_list (self ) -> None :
50
- def hider (secret_data : SecretData ) -> SecretData :
51
- if not isinstance (secret_data .secret , SecretAddress ):
52
- secret_data .secret = SecretAddress (url = "blah blah" )
53
- return secret_data
54
-
55
54
job_template_index = JobTemplateIndex (
56
55
name = "test" ,
57
56
template = JobTemplate (
@@ -100,12 +99,33 @@ def test_roundtrip_github_issue(self) -> None:
100
99
f"{ current_path } "
101
100
+ "/../../../contrib/onefuzz-job-github-actions/github-issues.json"
102
101
) as json_file :
103
- b = json .load (json_file )
104
- b ["container" ] = "testing"
105
- c = NotificationCreate .parse_obj (b )
106
- d = c .json ()
107
- e = json .loads (d )
108
- NotificationCreate .parse_obj (e )
102
+ notification_dict = json .load (json_file )
103
+ notification_dict ["container" ] = "testing"
104
+ notification1 = NotificationCreate .parse_obj (notification_dict )
105
+
106
+ assert isinstance (notification1 .config , GithubIssueTemplate )
107
+ self .assertIsInstance (
108
+ notification1 .config .auth .secret , GithubAuth , "Invalid secret type"
109
+ )
110
+
111
+ notification2 = NotificationCreate .parse_obj (
112
+ json .loads (notification1 .json ())
113
+ )
114
+
115
+ assert isinstance (notification2 .config , GithubIssueTemplate )
116
+ self .assertIsInstance (
117
+ notification2 .config .auth .secret , GithubAuth , "Invalid secret type"
118
+ )
119
+
120
+ hide_secrets (notification2 , hider )
121
+
122
+ notification3 = NotificationCreate .parse_obj (
123
+ json .loads (notification2 .json ())
124
+ )
125
+ assert isinstance (notification3 .config , GithubIssueTemplate )
126
+ self .assertIsInstance (
127
+ notification3 .config .auth .secret , SecretAddress , "Invalid secret type"
128
+ )
109
129
110
130
def test_roundtrip_team_issue (self ) -> None :
111
131
a = """
@@ -115,21 +135,59 @@ def test_roundtrip_team_issue(self) -> None:
115
135
}
116
136
117
137
""" # noqa
118
- b = json .loads (a )
119
- c = NotificationCreate .parse_obj (b )
120
- d = c .json ()
121
- e = json .loads (d )
122
- NotificationCreate .parse_obj (e )
138
+ notification_dict = json .loads (a )
139
+ notification_dict ["container" ] = "testing"
140
+ notification1 = NotificationCreate .parse_obj (notification_dict )
141
+
142
+ assert isinstance (notification1 .config , TeamsTemplate )
143
+ self .assertIsInstance (
144
+ notification1 .config .url .secret , str , "Invalid secret type"
145
+ )
146
+
147
+ notification2 = NotificationCreate .parse_obj (json .loads (notification1 .json ()))
148
+ assert isinstance (notification2 .config , TeamsTemplate )
149
+ self .assertIsInstance (
150
+ notification2 .config .url .secret , str , "Invalid secret type"
151
+ )
152
+
153
+ hide_secrets (notification2 , hider )
154
+
155
+ notification3 = NotificationCreate .parse_obj (json .loads (notification2 .json ()))
156
+ assert isinstance (notification3 .config , TeamsTemplate )
157
+ self .assertIsInstance (
158
+ notification3 .config .url .secret , SecretAddress , "Invalid secret type"
159
+ )
123
160
124
161
def test_roundtrip_ado (self ) -> None :
125
162
current_path = pathlib .Path (__file__ ).parent .absolute ()
126
163
with open (
127
164
f"{ current_path } "
128
165
+ "/../../../contrib/onefuzz-job-azure-devops-pipeline/ado-work-items.json" # noqa
129
166
) as json_file :
130
- b = json .load (json_file )
131
- b ["container" ] = "testing"
132
- c = NotificationCreate .parse_obj (b )
133
- d = c .json ()
134
- e = json .loads (d )
135
- NotificationCreate .parse_obj (e )
167
+ notification_dict = json .load (json_file )
168
+ notification_dict ["container" ] = "testing"
169
+ notification1 = NotificationCreate .parse_obj (notification_dict )
170
+ assert isinstance (notification1 .config , ADOTemplate )
171
+ self .assertIsInstance (
172
+ notification1 .config .auth_token .secret , str , "Invalid secret type"
173
+ )
174
+
175
+ notification2 = NotificationCreate .parse_obj (
176
+ json .loads (notification1 .json ())
177
+ )
178
+ assert isinstance (notification2 .config , ADOTemplate )
179
+ self .assertIsInstance (
180
+ notification2 .config .auth_token .secret , str , "Invalid secret type"
181
+ )
182
+
183
+ hide_secrets (notification2 , hider )
184
+
185
+ notification3 = NotificationCreate .parse_obj (
186
+ json .loads (notification2 .json ())
187
+ )
188
+ assert isinstance (notification3 .config , ADOTemplate )
189
+ self .assertIsInstance (
190
+ notification3 .config .auth_token .secret ,
191
+ SecretAddress ,
192
+ "Invalid secret type" ,
193
+ )
0 commit comments