Skip to content

Commit 9740741

Browse files
authored
[CI-5306] Limit the total size of uploaded XMLs (#242)
* [CI-5306] Limit the total size of uploaded XMLs * fix: change units from MB to MiB * fix: move const to the top of the file
1 parent a1c224d commit 9740741

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import (
2121
"github.com/hashicorp/go-retryablehttp"
2222
)
2323

24+
// maxTotalXMLSize limits the total size of all XML files uploaded in a single run
25+
const maxTotalXMLSize = 100 * 1024 * 1024 // 100 MiB
26+
2427
// FileInfo ...
2528
type FileInfo struct {
2629
FileName string `json:"filename"`
@@ -246,6 +249,10 @@ func ParseTestResults(testsRootDir string, useLegacyXCResultExtractionMethod boo
246249

247250
// Upload ...
248251
func (results Results) Upload(apiToken, endpointBaseURL, appSlug, buildSlug string, logger logV2.Logger) error {
252+
if results.calculateTotalSizeOfXMLContent() > maxTotalXMLSize {
253+
return fmt.Errorf("the total size of the test result XML files (%d MiB) exceeds the maximum allowed size of 100 MiB", results.calculateTotalSizeOfXMLContent()/1024/1024)
254+
}
255+
249256
for _, result := range results {
250257
logger.Printf("Uploading: %s", result.Name)
251258

@@ -308,3 +315,11 @@ func (results Results) Upload(apiToken, endpointBaseURL, appSlug, buildSlug stri
308315

309316
return nil
310317
}
318+
319+
func (results Results) calculateTotalSizeOfXMLContent() int {
320+
totalSize := 0
321+
for _, result := range results {
322+
totalSize += len(result.XMLContent)
323+
}
324+
return totalSize
325+
}

0 commit comments

Comments
 (0)