Skip to content

Commit

Permalink
Merge pull request #104 from isimluk/ci-scap
Browse files Browse the repository at this point in the history
Attempt to fix SCAP CI
  • Loading branch information
isimluk authored Nov 20, 2023
2 parents 505fa2d + a727541 commit 95911df
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/scap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ workdir=./scap/
mkdir -p $workdir
cat <<__END__ > $workdir/go.mod
module github.com/gocomply/scap
go 1.17
go 1.20
__END__

pushd $workdir
Expand All @@ -22,6 +22,7 @@ pushd $workdir

# Generage go code based on XSDs
$xsd2go convert .scap_schemas/schemas/cpe/2.3/cpe-dictionary_2.3.xsd github.com/gocomply/scap pkg/scap/models
go vet ./...
$xsd2go convert \
--xmlns-override=http://cpe.mitre.org/language/2.0=cpe_language \
.scap_schemas/schemas/xccdf/1.2/xccdf_1.2.xsd github.com/gocomply/scap pkg/scap/models
Expand Down
2 changes: 1 addition & 1 deletion pkg/template/pkged.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/template/types.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ import (
{{- if .ContainsText }}
Text string `xml:",chardata"`
{{- end}}
innerXml string `xml:",innerxml"`
{{- if .ContainsInnerXml }}
InnerXml string `xml:",innerxml"`
{{- end}}
}
{{end}}

Expand Down
4 changes: 4 additions & 0 deletions pkg/xsd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (ct *ComplexType) GoTypeName() string {
return ct.GoName()
}

func (ct *ComplexType) ContainsInnerXml() bool {
return ct.Mixed
}

func (ct *ComplexType) ContainsText() bool {
return ct.content != nil && ct.content.ContainsText()
}
Expand Down
7 changes: 3 additions & 4 deletions tests/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tests

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -21,14 +20,14 @@ func TestSanity(t *testing.T) {
for _, xsdPath := range xsdFiles {
actual := assertConvertsFine(t, xsdPath)

expected, err := ioutil.ReadFile(xsdPath + ".out")
expected, err := os.ReadFile(xsdPath + ".out")
require.NoError(t, err)
assert.Equal(t, string(expected), string(actual))
}
}

func assertConvertsFine(t *testing.T, xsdPath string) []byte {
dname, err := ioutil.TempDir("", "xsd2go_tests_")
dname, err := os.MkdirTemp("", "xsd2go_tests_")
assert.Nil(t, err)
defer os.RemoveAll(dname)

Expand All @@ -41,7 +40,7 @@ func assertConvertsFine(t *testing.T, xsdPath string) []byte {

generatedFilePath, err := locateGeneratedFile(outputDir)
require.NoError(t, err)
result, err := ioutil.ReadFile(generatedFilePath)
result, err := os.ReadFile(generatedFilePath)
require.NoError(t, err)

out, err := exec.Command("go", "build", generatedFilePath).Output()
Expand Down
2 changes: 0 additions & 2 deletions tests/xsd-examples/valid/complex.xsd.out
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ type MyElementType struct {
Id21 *int `xml:"id_21"`

Id22 *int `xml:"id_22"`

innerXml string `xml:",innerxml"`
}

// XSD SimpleType declarations
7 changes: 1 addition & 6 deletions tests/xsd-examples/valid/restriction.xsd.out
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ type StateRefType struct {
XMLName xml.Name

StateRef StateIdpattern `xml:"state_ref,attr"`

innerXml string `xml:",innerxml"`
}

type MySimpleBaseType struct {
Expand All @@ -32,8 +30,7 @@ type MySimpleBaseType struct {

Operation OperationEnumeration `xml:"operation,attr,omitempty"`

Text string `xml:",chardata"`
innerXml string `xml:",innerxml"`
Text string `xml:",chardata"`
}

type MyElementType struct {
Expand All @@ -42,8 +39,6 @@ type MyElementType struct {
Datatype DatatypeEnumeration `xml:"datatype,attr,omitempty"`

Operation OperationEnumeration `xml:"operation,attr,omitempty"`

innerXml string `xml:",innerxml"`
}

// XSD SimpleType declarations
Expand Down
2 changes: 0 additions & 2 deletions tests/xsd-examples/valid/simple-8859-1.xsd.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ type MyElementType struct {
XMLName xml.Name

Id int64 `xml:",any"`

innerXml string `xml:",innerxml"`
}

// XSD SimpleType declarations
2 changes: 0 additions & 2 deletions tests/xsd-examples/valid/simple.xsd.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ type MyElementType struct {
XMLName xml.Name

Id int64 `xml:",any"`

innerXml string `xml:",innerxml"`
}

// XSD SimpleType declarations
45 changes: 9 additions & 36 deletions tests/xsd-examples/valid/xmldsig-core-schema.xsd.out
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,14 @@ type SignatureType struct {
KeyInfo *KeyInfoType `xml:"KeyInfo"`

Object []ObjectType `xml:"Object"`

innerXml string `xml:",innerxml"`
}

type SignatureValueType struct {
XMLName xml.Name

Id string `xml:"Id,attr,omitempty"`

Text string `xml:",chardata"`
innerXml string `xml:",innerxml"`
Text string `xml:",chardata"`
}

type SignedInfoType struct {
Expand All @@ -287,16 +284,14 @@ type SignedInfoType struct {
SignatureMethod SignatureMethodType `xml:"SignatureMethod"`

Reference []ReferenceType `xml:"Reference"`

innerXml string `xml:",innerxml"`
}

type CanonicalizationMethodType struct {
XMLName xml.Name

Algorithm string `xml:"Algorithm,attr"`

innerXml string `xml:",innerxml"`
InnerXml string `xml:",innerxml"`
}

type SignatureMethodType struct {
Expand All @@ -306,7 +301,7 @@ type SignatureMethodType struct {

HmacoutputLength *HmacoutputLengthType `xml:",any"`

innerXml string `xml:",innerxml"`
InnerXml string `xml:",innerxml"`
}

type ReferenceType struct {
Expand All @@ -323,16 +318,12 @@ type ReferenceType struct {
DigestMethod DigestMethodType `xml:"DigestMethod"`

DigestValue DigestValueType `xml:"DigestValue"`

innerXml string `xml:",innerxml"`
}

type TransformsType struct {
XMLName xml.Name

Transform []TransformType `xml:",any"`

innerXml string `xml:",innerxml"`
}

type TransformType struct {
Expand All @@ -342,15 +333,15 @@ type TransformType struct {

Xpath []string `xml:"XPath"`

innerXml string `xml:",innerxml"`
InnerXml string `xml:",innerxml"`
}

type DigestMethodType struct {
XMLName xml.Name

Algorithm string `xml:"Algorithm,attr"`

innerXml string `xml:",innerxml"`
InnerXml string `xml:",innerxml"`
}

type KeyInfoType struct {
Expand All @@ -372,7 +363,7 @@ type KeyInfoType struct {

MgmtData []string `xml:"MgmtData"`

innerXml string `xml:",innerxml"`
InnerXml string `xml:",innerxml"`
}

type KeyValueType struct {
Expand All @@ -382,7 +373,7 @@ type KeyValueType struct {

RsakeyValue *RsakeyValueType `xml:"RSAKeyValue"`

innerXml string `xml:",innerxml"`
InnerXml string `xml:",innerxml"`
}

type RetrievalMethodType struct {
Expand All @@ -393,8 +384,6 @@ type RetrievalMethodType struct {
Type string `xml:"Type,attr,omitempty"`

Transforms *TransformsType `xml:",any"`

innerXml string `xml:",innerxml"`
}

type X509DataType struct {
Expand All @@ -409,8 +398,6 @@ type X509DataType struct {
X509Certificate string `xml:"X509Certificate"`

X509Crl string `xml:"X509CRL"`

innerXml string `xml:",innerxml"`
}

type X509IssuerSerialType struct {
Expand All @@ -419,8 +406,6 @@ type X509IssuerSerialType struct {
X509IssuerName string `xml:"X509IssuerName"`

X509SerialNumber int64 `xml:"X509SerialNumber"`

innerXml string `xml:",innerxml"`
}

type PgpdataType struct {
Expand All @@ -429,16 +414,12 @@ type PgpdataType struct {
PgpkeyId string `xml:"PGPKeyID"`

PgpkeyPacket string `xml:"PGPKeyPacket"`

innerXml string `xml:",innerxml"`
}

type SpkidataType struct {
XMLName xml.Name

Spkisexp string `xml:",any"`

innerXml string `xml:",innerxml"`
}

type ObjectType struct {
Expand All @@ -450,7 +431,7 @@ type ObjectType struct {

Encoding string `xml:"Encoding,attr,omitempty"`

innerXml string `xml:",innerxml"`
InnerXml string `xml:",innerxml"`
}

type ManifestType struct {
Expand All @@ -459,8 +440,6 @@ type ManifestType struct {
Id string `xml:"Id,attr,omitempty"`

Reference []ReferenceType `xml:",any"`

innerXml string `xml:",innerxml"`
}

type SignaturePropertiesType struct {
Expand All @@ -469,8 +448,6 @@ type SignaturePropertiesType struct {
Id string `xml:"Id,attr,omitempty"`

SignatureProperty []SignaturePropertyType `xml:",any"`

innerXml string `xml:",innerxml"`
}

type SignaturePropertyType struct {
Expand All @@ -480,7 +457,7 @@ type SignaturePropertyType struct {

Id string `xml:"Id,attr,omitempty"`

innerXml string `xml:",innerxml"`
InnerXml string `xml:",innerxml"`
}

type DsakeyValueType struct {
Expand All @@ -491,8 +468,6 @@ type DsakeyValueType struct {
Y CryptoBinary `xml:"Y"`

J *CryptoBinary `xml:"J"`

innerXml string `xml:",innerxml"`
}

type RsakeyValueType struct {
Expand All @@ -501,8 +476,6 @@ type RsakeyValueType struct {
Modulus CryptoBinary `xml:"Modulus"`

Exponent CryptoBinary `xml:"Exponent"`

innerXml string `xml:",innerxml"`
}

// XSD SimpleType declarations
Expand Down

0 comments on commit 95911df

Please sign in to comment.