Skip to content

Commit 7d30b00

Browse files
AST-21110
- Exported one new file with installation details, no need additional args. - Added new file installation.json with array of 2 versions: - Name + Version of 'Checkmarx Engine Service' + HotFix - name + Version of 'Checkmarx Queries Pack' + HotFix - Added unit tests
1 parent 2129bda commit 7d30b00

File tree

13 files changed

+406
-8
lines changed

13 files changed

+406
-8
lines changed

Diff for: Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ mocks:
5151
mockgen -package mock_interfaces -destination test/mocks/app/ast_query_mapping/mock_provider.go github.com/checkmarxDev/ast-sast-export/internal/app/interfaces QueryMappingRepo
5252
mockgen -package mock_interfaces -destination test/mocks/app/ast_query/mock_provider.go github.com/checkmarxDev/ast-sast-export/internal/app/interfaces ASTQueryProvider
5353
mockgen -package mock_preset_interfaces -destination test/mocks/app/preset/mock_provider.go github.com/checkmarxDev/ast-sast-export/internal/app/interfaces PresetProvider
54+
mockgen -package mock_installation_interfaces -destination test/mocks/app/installation/mock_provider.go github.com/checkmarxDev/ast-sast-export/internal/app/interfaces InstallationProvider

Diff for: internal/app/export/export.go

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const (
4343
PresetsDirName = "presets"
4444
// PresetsFileName presets file
4545
PresetsFileName = "presets.json"
46+
// InstallationFileName file
47+
InstallationFileName = "installation.json"
4648

4749
// DateTimeFormat the formal to use for DT
4850
DateTimeFormat = "2006-01-02-15-04-05"

Diff for: internal/app/export/transform.go

+25
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ import (
55
"regexp"
66
"strings"
77

8+
"github.com/checkmarxDev/ast-sast-export/internal/integration/soap"
9+
810
"github.com/checkmarxDev/ast-sast-export/internal/integration/rest"
911
)
1012

13+
const (
14+
installationEngineServiceName = "Checkmarx Engine Service"
15+
installationContentPackName = "Checkmarx Queries Pack"
16+
)
17+
1118
// TransformTeams flattens teams.
1219
func TransformTeams(teams []*rest.Team) []*rest.Team {
1320
out := make([]*rest.Team, 0)
@@ -43,6 +50,24 @@ func TransformSamlTeamMappings(samlTeamMappings []*rest.SamlTeamMapping) []*rest
4350
return out
4451
}
4552

53+
// TransformXMLInstallationMappings updates installation mapping.
54+
func TransformXMLInstallationMappings(installationMappings *soap.GetInstallationSettingsResponse) []*soap.InstallationMapping {
55+
out := make([]*soap.InstallationMapping, 0)
56+
if installationMappings == nil {
57+
return []*soap.InstallationMapping{}
58+
}
59+
for _, e := range installationMappings.GetInstallationSettingsResult.InstallationSettingsList.InstallationSetting {
60+
if e.Name == installationEngineServiceName || e.Name == installationContentPackName {
61+
out = append(out, &soap.InstallationMapping{
62+
Name: e.Name,
63+
Version: e.Version,
64+
Hotfix: e.Hotfix,
65+
})
66+
}
67+
}
68+
return out
69+
}
70+
4671
// TransformScanReport updates scan report in context of flatten teams.
4772
func TransformScanReport(xml []byte) ([]byte, error) {
4873
var teamPath string

Diff for: internal/app/export/transform_test.go

+107
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/checkmarxDev/ast-sast-export/internal/integration/soap"
8+
79
"github.com/checkmarxDev/ast-sast-export/internal/integration/rest"
810
"github.com/stretchr/testify/assert"
911
)
@@ -307,6 +309,111 @@ func TestReplaceKeyValue(t *testing.T) {
307309
})
308310
}
309311

312+
func TestTransformXMLInstallationMappings(t *testing.T) {
313+
t.Run("no installations", func(t *testing.T) {
314+
var installationMappings *soap.GetInstallationSettingsResponse
315+
316+
result := TransformXMLInstallationMappings(installationMappings)
317+
318+
var expected []*soap.InstallationMapping
319+
assert.ElementsMatch(t, expected, result)
320+
})
321+
322+
t.Run("only engine service", func(t *testing.T) {
323+
soapResponseSuccess := soap.GetInstallationSettingsResponse{
324+
GetInstallationSettingsResult: soap.GetInstallationSettingsResult{
325+
IsSuccesfull: "true",
326+
InstallationSettingsList: soap.InstallationSettingsList{
327+
InstallationSetting: soap.InstallationSetting{
328+
{
329+
Name: "Checkmarx Engine Service",
330+
Version: "9.3.4.1111",
331+
Hotfix: "Hotfix",
332+
},
333+
},
334+
},
335+
},
336+
}
337+
338+
result := TransformXMLInstallationMappings(&soapResponseSuccess)
339+
expected := []*soap.InstallationMapping{
340+
{
341+
Name: "Checkmarx Engine Service",
342+
Version: "9.3.4.1111",
343+
Hotfix: "Hotfix",
344+
},
345+
}
346+
347+
assert.ElementsMatch(t, expected, result)
348+
})
349+
350+
t.Run("only queries pack", func(t *testing.T) {
351+
soapResponseSuccess := soap.GetInstallationSettingsResponse{
352+
GetInstallationSettingsResult: soap.GetInstallationSettingsResult{
353+
IsSuccesfull: "true",
354+
InstallationSettingsList: soap.InstallationSettingsList{
355+
InstallationSetting: soap.InstallationSetting{
356+
{
357+
Name: "Checkmarx Queries Pack",
358+
Version: "9.3.4.5111",
359+
Hotfix: "Hotfix",
360+
},
361+
},
362+
},
363+
},
364+
}
365+
366+
result := TransformXMLInstallationMappings(&soapResponseSuccess)
367+
expected := []*soap.InstallationMapping{
368+
{
369+
Name: "Checkmarx Queries Pack",
370+
Version: "9.3.4.5111",
371+
Hotfix: "Hotfix",
372+
},
373+
}
374+
375+
assert.ElementsMatch(t, expected, result)
376+
})
377+
378+
t.Run("only both engine service and queries pack", func(t *testing.T) {
379+
soapResponseSuccess := soap.GetInstallationSettingsResponse{
380+
GetInstallationSettingsResult: soap.GetInstallationSettingsResult{
381+
IsSuccesfull: "true",
382+
InstallationSettingsList: soap.InstallationSettingsList{
383+
InstallationSetting: soap.InstallationSetting{
384+
{
385+
Name: "Checkmarx Engine Service",
386+
Version: "9.3.4.1111",
387+
Hotfix: "Hotfix",
388+
},
389+
{
390+
Name: "Checkmarx Queries Pack",
391+
Version: "9.3.4.5111",
392+
Hotfix: "Hotfix",
393+
},
394+
},
395+
},
396+
},
397+
}
398+
399+
result := TransformXMLInstallationMappings(&soapResponseSuccess)
400+
expected := []*soap.InstallationMapping{
401+
{
402+
Name: "Checkmarx Engine Service",
403+
Version: "9.3.4.1111",
404+
Hotfix: "Hotfix",
405+
},
406+
{
407+
Name: "Checkmarx Queries Pack",
408+
Version: "9.3.4.5111",
409+
Hotfix: "Hotfix",
410+
},
411+
}
412+
413+
assert.ElementsMatch(t, expected, result)
414+
})
415+
}
416+
310417
func newMockScanReportXML(teamName, teamFullPath string) string {
311418
// nolint:lll
312419
return fmt.Sprintf(`

Diff for: internal/app/interfaces/installation.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package interfaces
2+
3+
import "github.com/checkmarxDev/ast-sast-export/internal/integration/soap"
4+
5+
type InstallationProvider interface {
6+
GetInstallationSettings() (*soap.GetInstallationSettingsResponse, error)
7+
}

Diff for: internal/integration/soap/client.go

+28-5
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ import (
1313
)
1414

1515
const (
16-
errRequestMarshalFailed = "could not marshal request"
17-
errResponseUnmarshalFailed = "could not unmarshal response"
18-
errSoapCallFailed = "SOAP call failed"
19-
errCannotGetQueryList = "Cannot get Query list"
20-
errCannotGetPresetDetail = "Cannot get preset detail %d"
16+
errRequestMarshalFailed = "could not marshal request"
17+
errResponseUnmarshalFailed = "could not unmarshal response"
18+
errSoapCallFailed = "SOAP call failed"
19+
errCannotGetQueryList = "Cannot get Query list"
20+
errCannotGetPresetDetail = "Cannot get preset detail %d"
21+
errCannotGetInstallationDetail = "Cannot get installation detail"
2122
)
2223

2324
type Adapter interface {
2425
GetSourcesByScanID(scanID string, filenames []string) (*GetSourcesByScanIDResponse, error)
2526
GetResultPathsForQuery(scanID string, queryID string) (*GetResultPathsForQueryResponse, error)
2627
GetQueryCollection() (*GetQueryCollectionResponse, error)
2728
GetPresetDetails(ID int) (*GetPresetDetailsResponse, error)
29+
GetInstallationSettings() (*GetInstallationSettingsResponse, error)
2830
}
2931

3032
type Client struct {
@@ -131,6 +133,27 @@ func (e *Client) GetPresetDetails(id int) (*GetPresetDetailsResponse, error) {
131133
return &response, nil
132134
}
133135

136+
func (e *Client) GetInstallationSettings() (*GetInstallationSettingsResponse, error) {
137+
requestBytes, requestMarshalErr := xml.Marshal(GetInstallationSettingsRequest{})
138+
if requestMarshalErr != nil {
139+
return nil, errors.Wrap(requestMarshalErr, errRequestMarshalFailed)
140+
}
141+
envelope, callErr := e.call("GetInstallationSettings", requestBytes)
142+
if callErr != nil {
143+
return nil, errors.Wrap(callErr, errSoapCallFailed)
144+
}
145+
146+
var response GetInstallationSettingsResponse
147+
unmarshalErr := xml.Unmarshal(envelope.Body.Contents, &response)
148+
if unmarshalErr != nil {
149+
return nil, errors.Wrap(unmarshalErr, errResponseUnmarshalFailed)
150+
}
151+
if response.GetInstallationSettingsResult.IsSuccesfull != "true" {
152+
return nil, fmt.Errorf("%s: %s, response: %v", errSoapCallFailed, errCannotGetInstallationDetail, response)
153+
}
154+
return &response, nil
155+
}
156+
134157
func (e *Client) call(soapAction string, requestBytes []byte) (*Envelope, error) {
135158
body := fmt.Sprintf(`
136159
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:chec="http://Checkmarx.com">

Diff for: internal/integration/soap/models.go

+43
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,47 @@ type (
216216
XMLName xml.Name `xml:"queryIds"`
217217
Long []int `xml:"long"`
218218
}
219+
220+
// GetInstallationSettings request types
221+
222+
GetInstallationSettingsRequest struct {
223+
XMLName xml.Name `xml:"chec:GetInstallationSettings"`
224+
}
225+
226+
InstallationSetting []struct {
227+
XMLName xml.Name `xml:"InstallationSetting"`
228+
Text string `xml:",chardata"`
229+
Name string `xml:"Name"`
230+
ID string `xml:"ID"`
231+
DNSName string `xml:"DNSName"`
232+
IP string `xml:"IP"`
233+
State string `xml:"State"`
234+
Version string `xml:"Version"`
235+
Hotfix string `xml:"Hotfix"`
236+
InstllationPath string `xml:"InstllationPath"`
237+
IsInstalled string `xml:"IsInstalled"`
238+
}
239+
240+
InstallationSettingsList struct {
241+
XMLName xml.Name `xml:"InstallationSettingsList"`
242+
InstallationSetting InstallationSetting `xml:"InstallationSetting"`
243+
}
244+
245+
GetInstallationSettingsResult struct {
246+
XMLName xml.Name `xml:"GetInstallationSettingsResult"`
247+
IsSuccesfull string `xml:"IsSuccesfull"`
248+
InstallationSettingsList InstallationSettingsList `xml:"InstallationSettingsList"`
249+
}
250+
251+
GetInstallationSettingsResponse struct {
252+
Text string `xml:",chardata"`
253+
Xmlns string `xml:"xmlns,attr"`
254+
GetInstallationSettingsResult GetInstallationSettingsResult `xml:"GetInstallationSettingsResult"`
255+
}
256+
257+
InstallationMapping struct {
258+
Name string `json:"name"`
259+
Version string `json:"version"`
260+
Hotfix string `json:"hotFix"`
261+
}
219262
)

Diff for: internal/persistence/installation/repo.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package installation
2+
3+
import "github.com/checkmarxDev/ast-sast-export/internal/integration/soap"
4+
5+
type Repo struct {
6+
soapClient soap.Adapter
7+
}
8+
9+
func NewRepo(soapClient soap.Adapter) *Repo {
10+
return &Repo{soapClient: soapClient}
11+
}
12+
13+
func (e *Repo) GetInstallationSettings() (*soap.GetInstallationSettingsResponse, error) {
14+
return e.soapClient.GetInstallationSettings()
15+
}

Diff for: internal/persistence/installation/repo_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package installation
2+
3+
import (
4+
"testing"
5+
6+
mock_integration_soap "github.com/checkmarxDev/ast-sast-export/test/mocks/integration/soap"
7+
8+
"github.com/checkmarxDev/ast-sast-export/internal/integration/soap"
9+
"github.com/golang/mock/gomock"
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
var (
14+
soapResponseSuccess = soap.GetInstallationSettingsResponse{
15+
GetInstallationSettingsResult: soap.GetInstallationSettingsResult{
16+
IsSuccesfull: "true",
17+
InstallationSettingsList: soap.InstallationSettingsList{
18+
InstallationSetting: soap.InstallationSetting{
19+
{
20+
Name: "Checkmarx Engine Service",
21+
Version: "9.3.4.1111",
22+
Hotfix: "Hotfix",
23+
},
24+
{
25+
Name: "Checkmarx Queries Pack",
26+
Version: "9.3.4.5111",
27+
Hotfix: "Hotfix",
28+
},
29+
},
30+
},
31+
},
32+
}
33+
)
34+
35+
func TestRepo_GetInstallationSettings(t *testing.T) {
36+
ctrl := gomock.NewController(t)
37+
soapClientMock := mock_integration_soap.NewMockAdapter(ctrl)
38+
soapClientMock.EXPECT().GetInstallationSettings().Return(&soapResponseSuccess, nil)
39+
instance := NewRepo(soapClientMock)
40+
41+
result, err := instance.GetInstallationSettings()
42+
assert.NoError(t, err)
43+
assert.Equal(t, &soapResponseSuccess, result)
44+
}

0 commit comments

Comments
 (0)