@@ -29,9 +29,10 @@ import (
29
29
"testing"
30
30
31
31
"github.com/arduino/arduino-create-agent/config"
32
- "github.com/arduino/arduino-create-agent/gen/tools"
32
+ genTools "github.com/arduino/arduino-create-agent/gen/tools"
33
33
"github.com/arduino/arduino-create-agent/globals"
34
34
"github.com/arduino/arduino-create-agent/index"
35
+ "github.com/arduino/arduino-create-agent/tools"
35
36
"github.com/arduino/arduino-create-agent/upload"
36
37
"github.com/arduino/arduino-create-agent/utilities"
37
38
v2 "github.com/arduino/arduino-create-agent/v2"
@@ -56,7 +57,15 @@ func TestValidSignatureKey(t *testing.T) {
56
57
57
58
func TestUploadHandlerAgainstEvilFileNames (t * testing.T ) {
58
59
r := gin .New ()
59
- r .POST ("/" , uploadHandler (newHub (newSerialHub (), newSerialPortList ()), utilities .MustParseRsaPublicKey ([]byte (globals .ArduinoSignaturePubKey ))))
60
+
61
+ index := index .Init (* indexURL , config .GetDataDir ())
62
+ signaturePubKey , err := utilities .ParseRsaPublicKey ([]byte (* signatureKey ))
63
+ require .NoError (t , err )
64
+ tools := tools .New (config .GetDataDir (), index , signaturePubKey )
65
+ hub := newHub (newSerialHub (), newSerialPortList (tools ), tools )
66
+ pubkey := utilities .MustParseRsaPublicKey ([]byte (globals .ArduinoSignaturePubKey ))
67
+
68
+ r .POST ("/" , uploadHandler (hub , pubkey , tools ))
60
69
ts := httptest .NewServer (r )
61
70
62
71
uploadEvilFileName := Upload {
@@ -93,7 +102,14 @@ func TestUploadHandlerAgainstEvilFileNames(t *testing.T) {
93
102
func TestUploadHandlerAgainstBase64WithoutPaddingMustFail (t * testing.T ) {
94
103
r := gin .New ()
95
104
96
- r .POST ("/" , uploadHandler (newHub (newSerialHub (), newSerialPortList ()), utilities .MustParseRsaPublicKey ([]byte (globals .ArduinoSignaturePubKey ))))
105
+ index := index .Init (* indexURL , config .GetDataDir ())
106
+ signaturePubKey , err := utilities .ParseRsaPublicKey ([]byte (* signatureKey ))
107
+ require .NoError (t , err )
108
+ tools := tools .New (config .GetDataDir (), index , signaturePubKey )
109
+ hub := newHub (newSerialHub (), newSerialPortList (tools ), tools )
110
+ pubkey := utilities .MustParseRsaPublicKey ([]byte (globals .ArduinoSignaturePubKey ))
111
+
112
+ r .POST ("/" , uploadHandler (hub , pubkey , tools ))
97
113
ts := httptest .NewServer (r )
98
114
defer ts .Close ()
99
115
@@ -127,15 +143,15 @@ func TestInstallToolV2(t *testing.T) {
127
143
ts := httptest .NewServer (r )
128
144
129
145
type test struct {
130
- request tools .ToolPayload
146
+ request genTools .ToolPayload
131
147
responseCode int
132
148
responseBody string
133
149
}
134
150
135
151
bossacURL := "http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"
136
152
bossacChecksum := "SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"
137
153
bossacSignature := "382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"
138
- bossacInstallURLOK := tools .ToolPayload {
154
+ bossacInstallURLOK := genTools .ToolPayload {
139
155
Name : "bossac" ,
140
156
Version : "1.7.0-arduino3" ,
141
157
Packager : "arduino" ,
@@ -147,7 +163,7 @@ func TestInstallToolV2(t *testing.T) {
147
163
esptoolURL := "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/x86_64-linux-gnu.esptool-f80ae31.tar.gz"
148
164
esptoolChecksum := "SHA-256:bded1dca953377838b6086a9bcd40a1dc5286ba5f69f2372c22a1d1819baad24"
149
165
esptoolSignature := "852b58871419ce5e5633ecfaa72c0f0fa890ceb51164b362b8133bc0e3e003a21cec48935b8cdc078f4031219cbf17fb7edd9d7c9ca8ed85492911c9ca6353c9aa4691eb91fda99563a6bd49aeca0d9981fb05ec76e45c6024f8a6822862ad1e34ddc652fbbf4fa909887a255d4f087398ec386577efcec523c21203be3d10fc9e9b0f990a7536875a77dc2bc5cbffea7734b62238e31719111b718bacccebffc9be689545540e81d23b81caa66214376f58a0d6a45cf7efc5d3af62ab932b371628162fffe403906f41d5534921e5be081c5ac2ecc9db5caec03a105cc44b00ce19a95ad079843501eb8182e0717ce327867380c0e39d2b48698547fc1d0d66"
150
- esptoolInstallURLOK := tools .ToolPayload {
166
+ esptoolInstallURLOK := genTools .ToolPayload {
151
167
Name : "esptool" ,
152
168
Version : "2.5.0-3-20ed2b9" ,
153
169
Packager : "esp8266" ,
@@ -157,7 +173,7 @@ func TestInstallToolV2(t *testing.T) {
157
173
}
158
174
159
175
wrongSignature := "wr0ngs1gn4tur3"
160
- bossacInstallWrongSig := tools .ToolPayload {
176
+ bossacInstallWrongSig := genTools .ToolPayload {
161
177
Name : "bossac" ,
162
178
Version : "1.7.0-arduino3" ,
163
179
Packager : "arduino" ,
@@ -167,7 +183,7 @@ func TestInstallToolV2(t *testing.T) {
167
183
}
168
184
169
185
wrongChecksum := "wr0ngch3cksum"
170
- bossacInstallWrongCheck := tools .ToolPayload {
186
+ bossacInstallWrongCheck := genTools .ToolPayload {
171
187
Name : "bossac" ,
172
188
Version : "1.7.0-arduino3" ,
173
189
Packager : "arduino" ,
@@ -176,7 +192,7 @@ func TestInstallToolV2(t *testing.T) {
176
192
Signature : & bossacSignature ,
177
193
}
178
194
179
- bossacInstallNoURL := tools .ToolPayload {
195
+ bossacInstallNoURL := genTools .ToolPayload {
180
196
Name : "bossac" ,
181
197
Version : "1.7.0-arduino3" ,
182
198
Packager : "arduino" ,
0 commit comments