@@ -29,9 +29,10 @@ import (
2929 "testing"
3030
3131 "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"
3333 "github.com/arduino/arduino-create-agent/globals"
3434 "github.com/arduino/arduino-create-agent/index"
35+ "github.com/arduino/arduino-create-agent/tools"
3536 "github.com/arduino/arduino-create-agent/upload"
3637 "github.com/arduino/arduino-create-agent/utilities"
3738 v2 "github.com/arduino/arduino-create-agent/v2"
@@ -56,7 +57,15 @@ func TestValidSignatureKey(t *testing.T) {
5657
5758func TestUploadHandlerAgainstEvilFileNames (t * testing.T ) {
5859 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 ))
6069 ts := httptest .NewServer (r )
6170
6271 uploadEvilFileName := Upload {
@@ -93,7 +102,14 @@ func TestUploadHandlerAgainstEvilFileNames(t *testing.T) {
93102func TestUploadHandlerAgainstBase64WithoutPaddingMustFail (t * testing.T ) {
94103 r := gin .New ()
95104
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 ))
97113 ts := httptest .NewServer (r )
98114 defer ts .Close ()
99115
@@ -127,15 +143,15 @@ func TestInstallToolV2(t *testing.T) {
127143 ts := httptest .NewServer (r )
128144
129145 type test struct {
130- request tools .ToolPayload
146+ request genTools .ToolPayload
131147 responseCode int
132148 responseBody string
133149 }
134150
135151 bossacURL := "http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"
136152 bossacChecksum := "SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"
137153 bossacSignature := "382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"
138- bossacInstallURLOK := tools .ToolPayload {
154+ bossacInstallURLOK := genTools .ToolPayload {
139155 Name : "bossac" ,
140156 Version : "1.7.0-arduino3" ,
141157 Packager : "arduino" ,
@@ -147,7 +163,7 @@ func TestInstallToolV2(t *testing.T) {
147163 esptoolURL := "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/x86_64-linux-gnu.esptool-f80ae31.tar.gz"
148164 esptoolChecksum := "SHA-256:bded1dca953377838b6086a9bcd40a1dc5286ba5f69f2372c22a1d1819baad24"
149165 esptoolSignature := "852b58871419ce5e5633ecfaa72c0f0fa890ceb51164b362b8133bc0e3e003a21cec48935b8cdc078f4031219cbf17fb7edd9d7c9ca8ed85492911c9ca6353c9aa4691eb91fda99563a6bd49aeca0d9981fb05ec76e45c6024f8a6822862ad1e34ddc652fbbf4fa909887a255d4f087398ec386577efcec523c21203be3d10fc9e9b0f990a7536875a77dc2bc5cbffea7734b62238e31719111b718bacccebffc9be689545540e81d23b81caa66214376f58a0d6a45cf7efc5d3af62ab932b371628162fffe403906f41d5534921e5be081c5ac2ecc9db5caec03a105cc44b00ce19a95ad079843501eb8182e0717ce327867380c0e39d2b48698547fc1d0d66"
150- esptoolInstallURLOK := tools .ToolPayload {
166+ esptoolInstallURLOK := genTools .ToolPayload {
151167 Name : "esptool" ,
152168 Version : "2.5.0-3-20ed2b9" ,
153169 Packager : "esp8266" ,
@@ -157,7 +173,7 @@ func TestInstallToolV2(t *testing.T) {
157173 }
158174
159175 wrongSignature := "wr0ngs1gn4tur3"
160- bossacInstallWrongSig := tools .ToolPayload {
176+ bossacInstallWrongSig := genTools .ToolPayload {
161177 Name : "bossac" ,
162178 Version : "1.7.0-arduino3" ,
163179 Packager : "arduino" ,
@@ -167,7 +183,7 @@ func TestInstallToolV2(t *testing.T) {
167183 }
168184
169185 wrongChecksum := "wr0ngch3cksum"
170- bossacInstallWrongCheck := tools .ToolPayload {
186+ bossacInstallWrongCheck := genTools .ToolPayload {
171187 Name : "bossac" ,
172188 Version : "1.7.0-arduino3" ,
173189 Packager : "arduino" ,
@@ -176,7 +192,7 @@ func TestInstallToolV2(t *testing.T) {
176192 Signature : & bossacSignature ,
177193 }
178194
179- bossacInstallNoURL := tools .ToolPayload {
195+ bossacInstallNoURL := genTools .ToolPayload {
180196 Name : "bossac" ,
181197 Version : "1.7.0-arduino3" ,
182198 Packager : "arduino" ,
0 commit comments