diff --git a/cmd/mapTool/main.go b/cmd/mapTool/main.go index d2b8e23..21a10e7 100644 --- a/cmd/mapTool/main.go +++ b/cmd/mapTool/main.go @@ -33,7 +33,7 @@ mapTool -t= [-parse] [-o=] ` func main() { - x := hexapolicy.PolicyInfoSaurabh{Name: "Saurabh"} + x := hexapolicy.PolicyInfoSaurabhV2{Name: "Saurabh"} fmt.Println(x) isForward := true diff --git a/cmd/mapTool/map_test.go b/cmd/mapTool/map_test.go index 3da1387..d719524 100644 --- a/cmd/mapTool/map_test.go +++ b/cmd/mapTool/map_test.go @@ -1,70 +1,75 @@ package main import ( - "os" - "path/filepath" - "testing" - - "github.com/hexa-org/policy-mapper/hexaIdql/pkg/hexapolicysupport" - "github.com/stretchr/testify/assert" + "fmt" + "github.com/hexa-org/policy-mapper/hexaIdql/pkg/hexapolicy" + "os" + "path/filepath" + "testing" + + "github.com/hexa-org/policy-mapper/hexaIdql/pkg/hexapolicysupport" + "github.com/stretchr/testify/assert" ) func TestIdqlAndCedar(t *testing.T) { - // Map a simple file over to Cedar and then parse it back to Idql to test mapping in both directions - testIdqlFilename := "examples/idqlAlice.json" + x := hexapolicy.PolicyInfoSaurabhV2{Name: "Saurabh"} + fmt.Println(x) + + // Map a simple file over to Cedar and then parse it back to Idql to test mapping in both directions + testIdqlFilename := "examples/idqlAlice.json" - target = "awsCedar" + target = "awsCedar" - dir, _ := os.MkdirTemp(os.TempDir(), "hexaMapper-*") + dir, _ := os.MkdirTemp(os.TempDir(), "hexaMapper-*") - output = filepath.Join(dir, "aliceOut.txt") + output = filepath.Join(dir, "aliceOut.txt") - idqlToPlatform(testIdqlFilename) + idqlToPlatform(testIdqlFilename) - cedarFile := output + cedarFile := output - output = filepath.Join(dir, "idqlAliceBack.json") + output = filepath.Join(dir, "idqlAliceBack.json") - platformToIdql(cedarFile) + platformToIdql(cedarFile) - idqlResBytes, err := os.ReadFile(output) - assert.NoError(t, err, "Error reading idql output file") - origBytes, _ := os.ReadFile(testIdqlFilename) + idqlResBytes, err := os.ReadFile(output) + assert.NoError(t, err, "Error reading idql output file") + origBytes, _ := os.ReadFile(testIdqlFilename) - assert.Equal(t, len(idqlResBytes), len(origBytes), "Original and result are the same") + assert.Equal(t, len(idqlResBytes), len(origBytes), "Original and result are the same") - os.Remove(cedarFile) - os.Remove(output) - os.Remove(dir) + os.Remove(cedarFile) + os.Remove(output) + os.Remove(dir) } func TestIdqlAndGcp(t *testing.T) { - // Map a simple file over to GCP and then parse it back to Idql to test mapping in both directions - // This also exercises the condition mapper - testIdqlFilename := "examples/example_idql.json" + // Map a simple file over to GCP and then parse it back to Idql to test mapping in both directions + // This also exercises the condition mapper + testIdqlFilename := "examples/example_idql.json" - target = "gcpBind" + target = "gcpBind" - dir, _ := os.MkdirTemp(os.TempDir(), "hexaMapper-*") + dir, _ := os.MkdirTemp(os.TempDir(), "hexaMapper-*") - output = filepath.Join(dir, "gcpOut.json") + output = filepath.Join(dir, "gcpOut.json") - idqlToPlatform(testIdqlFilename) + idqlToPlatform(testIdqlFilename) - gcpFile := output + gcpFile := output - output = filepath.Join(dir, "idqlGcpBack.json") + output = filepath.Join(dir, "idqlGcpBack.json") - platformToIdql(gcpFile) + platformToIdql(gcpFile) - policiesOrig, err := hexapolicysupport.ParsePolicyFile(testIdqlFilename) - assert.NoError(t, err, "Error parsing original policy file") - policiesRoundTrip, err := hexapolicysupport.ParsePolicyFile(output) - assert.NoError(t, err, "Error parsing round trip policy file") + policiesOrig, err := hexapolicysupport.ParsePolicyFile(testIdqlFilename) + assert.NoError(t, err, "Error parsing original policy file") + policiesRoundTrip, err := hexapolicysupport.ParsePolicyFile(output) + assert.NoError(t, err, "Error parsing round trip policy file") - assert.Equal(t, len(policiesOrig), len(policiesRoundTrip), "Original and result are the same") + assert.Equal(t, len(policiesOrig), len(policiesRoundTrip), "Original and result are the same") - os.Remove(gcpFile) - os.Remove(output) - os.Remove(dir) + os.Remove(gcpFile) + os.Remove(output) + os.Remove(dir) } diff --git a/hexaIdql/pkg/hexapolicy/hexa_policy.go b/hexaIdql/pkg/hexapolicy/hexa_policy.go index 1e4834b..ad5d08a 100644 --- a/hexaIdql/pkg/hexapolicy/hexa_policy.go +++ b/hexaIdql/pkg/hexapolicy/hexa_policy.go @@ -31,6 +31,10 @@ type PolicyInfoSaurabh struct { Name string } +type PolicyInfoSaurabhV2 struct { + Name string +} + type PolicyInfo struct { Meta MetaInfo `validate:"required"` Subject SubjectInfo `validate:"required"`