Skip to content

Commit

Permalink
adding local files before rebase sign
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh-io committed Sep 12, 2023
1 parent 6c07f12 commit 8020a96
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 41 deletions.
2 changes: 1 addition & 1 deletion cmd/mapTool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mapTool -t=<awsCedar|gcpbind> [-parse] [-o=<output>] <input>
`

func main() {
x := hexapolicy.PolicyInfoSaurabh{Name: "Saurabh"}
x := hexapolicy.PolicyInfoSaurabhV2{Name: "Saurabh"}
fmt.Println(x)

isForward := true
Expand Down
85 changes: 45 additions & 40 deletions cmd/mapTool/map_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 4 additions & 0 deletions hexaIdql/pkg/hexapolicy/hexa_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 8020a96

Please sign in to comment.