2021-08-18 18:37:43 +03:00
|
|
|
package format
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/model"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/model/types/severity"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/model/types/stringslice"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/reporting/exporters/markdown/util"
|
2024-03-13 02:27:15 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-08-18 18:37:43 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestToMarkdownTableString(t *testing.T) {
|
|
|
|
|
info := model.Info{
|
|
|
|
|
Name: "Test Template Name",
|
2021-09-03 16:48:39 +03:00
|
|
|
Authors: stringslice.StringSlice{Value: []string{"forgedhallpass", "ice3man"}},
|
2021-08-18 18:37:43 +03:00
|
|
|
Description: "Test description",
|
2021-09-03 16:48:39 +03:00
|
|
|
SeverityHolder: severity.Holder{Severity: severity.High},
|
|
|
|
|
Tags: stringslice.StringSlice{Value: []string{"cve", "misc"}},
|
2023-07-28 10:18:15 -04:00
|
|
|
Reference: stringslice.NewRawStringSlice("reference1"),
|
2022-02-27 22:28:00 +08:00
|
|
|
Metadata: map[string]interface{}{
|
2021-08-18 18:37:43 +03:00
|
|
|
"customDynamicKey1": "customDynamicValue1",
|
|
|
|
|
"customDynamicKey2": "customDynamicValue2",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 14:27:32 +03:00
|
|
|
result := CreateTemplateInfoTable(&info, &util.MarkdownFormatter{})
|
2021-08-18 18:37:43 +03:00
|
|
|
|
2023-06-22 14:27:32 +03:00
|
|
|
expectedOrderedAttributes := `| Key | Value |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
| Name | Test Template Name |
|
2021-08-18 18:37:43 +03:00
|
|
|
| Authors | forgedhallpass, ice3man |
|
|
|
|
|
| Tags | cve, misc |
|
|
|
|
|
| Severity | high |
|
|
|
|
|
| Description | Test description |`
|
|
|
|
|
|
|
|
|
|
expectedDynamicAttributes := []string{
|
|
|
|
|
"| customDynamicKey1 | customDynamicValue1 |",
|
|
|
|
|
"| customDynamicKey2 | customDynamicValue2 |",
|
|
|
|
|
"", // the expected result ends in a new line (\n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actualAttributeSlice := strings.Split(result, "\n")
|
|
|
|
|
dynamicAttributeIndex := len(actualAttributeSlice) - len(expectedDynamicAttributes)
|
2024-03-13 02:27:15 +01:00
|
|
|
require.Equal(t, strings.Split(expectedOrderedAttributes, "\n"), actualAttributeSlice[:dynamicAttributeIndex]) // the first part of the result is ordered
|
|
|
|
|
require.ElementsMatch(t, expectedDynamicAttributes, actualAttributeSlice[dynamicAttributeIndex:]) // dynamic parameters are not ordered
|
2021-08-18 18:37:43 +03:00
|
|
|
}
|