Skip to content

Commit

Permalink
feat: prosast component data upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-stewart committed Jun 6, 2024
1 parent 02bccca commit 33554ab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/component_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type ComponentDataService struct {

const URL_TYPE_DEFAULT = "Default"
const URL_TYPE_SAST_TABLES = "SastTables"
const URL_TYPE_PROSAST = "ProSast"

var URL_TYPES = []string{URL_TYPE_DEFAULT, URL_TYPE_SAST_TABLES}
var URL_TYPES = []string{URL_TYPE_DEFAULT, URL_TYPE_SAST_TABLES, URL_TYPE_PROSAST}

type ComponentDataInitialRequest struct {
Name string `json:"name"`
Expand Down Expand Up @@ -70,6 +71,10 @@ func (svc *ComponentDataService) UploadSastTables(
return svc.doUploadFiles(name, []string{"sast"}, paths, URL_TYPE_SAST_TABLES)
}

func (svc *ComponentDataService) UploadProSast(name string, paths []string) (string, error) {
return svc.doUploadFiles(name, []string{"sast"}, paths, URL_TYPE_PROSAST)
}

func (svc *ComponentDataService) doUploadFiles(
name string, tags []string, paths []string, urlType string) (string, error) {
var hasValidType = false
Expand Down
30 changes: 30 additions & 0 deletions api/component_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,36 @@ func TestSastTablesUrlType(t *testing.T) {
assert.Equal(t, "SOME-GUID", guid)
}

func TestProSastUrlType(t *testing.T) {
fakeServer := lacework.MockServer()
fakeServer.MockToken("TOKEN")
defer fakeServer.Close()
fakeServer.MockAPI("ComponentData/requestUpload", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "POST", r.Method)
assert.NotNil(t, r.Body)
body := httpBodySniffer(r)
assert.Contains(t, body, api.URL_TYPE_PROSAST)
_, err := fmt.Fprint(w, generateInitialResponse())
assert.Nil(t, err)
})
fakeServer.MockAPI("ComponentData/completeUpload", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "POST", r.Method)
assert.NotNil(t, r.Body)
body := httpBodySniffer(r)
assert.Contains(t, body, api.URL_TYPE_PROSAST)
_, err := fmt.Fprint(w, generateCompleteResponse())
assert.Nil(t, err)
})
c, err := api.NewClient("test",
api.WithToken("TOKEN"),
api.WithURL(fakeServer.URL()),
)
assert.Nil(t, err)
guid, err := c.V2.ComponentData.UploadProSast("doc-set", []string{})
assert.Nil(t, err)
assert.Equal(t, "SOME-GUID", guid)
}

func TestDoWithExponentialBackoffAlwaysFailing(t *testing.T) {
waited := 0
err := api.DoWithExponentialBackoff(func() error {
Expand Down

0 comments on commit 33554ab

Please sign in to comment.