forked from raystack/frontier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable resource identifier composing from multiple variables
- Loading branch information
1 parent
ea97a84
commit 6303132
Showing
10 changed files
with
211 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package proxy | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/valyala/fasttemplate" | ||
) | ||
|
||
func ComposeAttribute(attribute string, attrs map[string]interface{}) string { | ||
if strings.Contains(attribute, "{") { | ||
template := fasttemplate.New(attribute, "{", "}") | ||
return template.ExecuteString(attrs) | ||
} | ||
return attribute | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,6 +424,80 @@ func (s *EndToEndProxySmokeTestSuite) TestProxyToEchoServer() { | |
} | ||
s.Assert().Equal(s.userID, subjectID) | ||
}) | ||
s.Run("resource created on echo server should persist in shieldDB when using composite variable", func() { | ||
userDetail, err := s.client.GetUser(context.Background(), &shieldv1beta1.GetUserRequest{Id: s.userID}) | ||
s.Require().NoError(err) | ||
|
||
url := fmt.Sprintf("http://localhost:%d/api/resource_composite/test-name", s.appConfig.Proxy.Services[0].Port) | ||
reqBodyMap := map[string]string{ | ||
"project": s.projID, | ||
"user_email": userDetail.GetUser().GetEmail(), | ||
} | ||
reqBodyBytes, err := json.Marshal(reqBodyMap) | ||
s.Require().NoError(err) | ||
|
||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(reqBodyBytes)) | ||
s.Require().NoError(err) | ||
|
||
req.Header.Set(testbench.IdentityHeader, "[email protected]") | ||
req.Header.Set("X-Shield-Org", s.orgID) | ||
|
||
res, err := http.DefaultClient.Do(req) | ||
s.Require().NoError(err) | ||
|
||
defer res.Body.Close() | ||
|
||
s.Assert().Equal(200, res.StatusCode) | ||
|
||
resourceSelectQuery := "SELECT name FROM resources" | ||
resources, err := s.dbClient.Query(resourceSelectQuery) | ||
s.Require().NoError(err) | ||
defer resources.Close() | ||
|
||
resourceName := "" | ||
for resources.Next() { | ||
if err := resources.Scan(&resourceName); err != nil { | ||
s.Require().NoError(err) | ||
} | ||
} | ||
s.Assert().Equal(fmt.Sprintf("%s-test-name", s.projID), resourceName) | ||
|
||
relationSelectQuery := "SELECT subject_id FROM relations ORDER BY created_at DESC LIMIT 1" | ||
relations, err := s.dbClient.Query(relationSelectQuery) | ||
s.Require().NoError(err) | ||
defer resources.Close() | ||
|
||
subjectID := "" | ||
for relations.Next() { | ||
if err := relations.Scan(&subjectID); err != nil { | ||
s.Require().NoError(err) | ||
} | ||
} | ||
s.Assert().Equal(s.userID, subjectID) | ||
}) | ||
s.Run("permission expression: permission resource can be composed using multiple variable", func() { | ||
userDetail, err := s.client.GetUser(context.Background(), &shieldv1beta1.GetUserRequest{Id: s.userID}) | ||
s.Require().NoError(err) | ||
|
||
url := fmt.Sprintf("http://localhost:%d/api/update_firehose_based_on_sink/test-name", s.appConfig.Proxy.Services[0].Port) | ||
reqBodyMap := map[string]any{ | ||
"organization": s.orgSlug, | ||
"project": s.projID, | ||
} | ||
reqBodyBytes, err := json.Marshal(reqBodyMap) | ||
s.Require().NoError(err) | ||
|
||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(reqBodyBytes)) | ||
s.Require().NoError(err) | ||
|
||
req.Header.Set(testbench.IdentityHeader, userDetail.GetUser().GetEmail()) | ||
|
||
res, err := http.DefaultClient.Do(req) | ||
s.Require().NoError(err) | ||
|
||
defer res.Body.Close() | ||
s.Assert().Equal(200, res.StatusCode) | ||
}) | ||
} | ||
|
||
func TestEndToEndProxySmokeTestSuite(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters