Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions service/integration/subject_mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ func (s *SubjectMappingsSuite) TestUpdateSubjectConditionSet_NonExistentId_Fails

func (s *SubjectMappingsSuite) TestGetMatchedSubjectMappings_SingleMatch() {
externalSelector := ".testing_matched_sm"
fixtureAttrValID := s.f.GetAttributeValueKey("example.com/attr/attr1/value/value1").ID
fixtureAttrVal := s.f.GetAttributeValueKey("example.com/attr/attr1/value/value1")
newScs := &subjectmapping.SubjectConditionSetCreate{
SubjectSets: []*policy.SubjectSet{
{
Expand All @@ -1246,7 +1246,7 @@ func (s *SubjectMappingsSuite) TestGetMatchedSubjectMappings_SingleMatch() {
}

subjectMapping := &subjectmapping.CreateSubjectMappingRequest{
AttributeValueId: fixtureAttrValID,
AttributeValueId: fixtureAttrVal.ID,
Actions: []*policy.Action{s.f.GetStandardAction("create")},
NewSubjectConditionSet: newScs,
}
Expand All @@ -1265,14 +1265,15 @@ func (s *SubjectMappingsSuite) TestGetMatchedSubjectMappings_SingleMatch() {
s.NotZero(smList)
matched := smList[0]
s.Equal(created.GetId(), matched.GetId())
s.NotZero(matched.GetAttributeValue().GetId())
s.Equal(matched.GetAttributeValue().GetId(), fixtureAttrVal.ID)
s.True(strings.HasSuffix(matched.GetAttributeValue().GetFqn(), fixtureAttrVal.Value))
s.NotZero(matched.GetId())
s.NotNil(matched.GetActions())
}

func (s *SubjectMappingsSuite) TestGetMatchedSubjectMappings_IgnoresExternalValueInCondition() {
externalSelector := ".testing_unmatched_condition"
fixtureAttrValID := s.f.GetAttributeValueKey("example.com/attr/attr2/value/value2").ID
fixtureAttrVal := s.f.GetAttributeValueKey("example.com/attr/attr2/value/value2")
newScs := &subjectmapping.SubjectConditionSetCreate{
SubjectSets: []*policy.SubjectSet{
{
Expand All @@ -1293,7 +1294,7 @@ func (s *SubjectMappingsSuite) TestGetMatchedSubjectMappings_IgnoresExternalValu
}

subjectMapping := &subjectmapping.CreateSubjectMappingRequest{
AttributeValueId: fixtureAttrValID,
AttributeValueId: fixtureAttrVal.ID,
Actions: []*policy.Action{s.f.GetStandardAction("delete")},
NewSubjectConditionSet: newScs,
}
Expand All @@ -1313,7 +1314,9 @@ func (s *SubjectMappingsSuite) TestGetMatchedSubjectMappings_IgnoresExternalValu
s.NotZero(smList)
matched := smList[0]
s.Equal(created.GetId(), matched.GetId())
s.NotZero(matched.GetAttributeValue().GetId())
s.Equal(matched.GetAttributeValue().GetId(), fixtureAttrVal.ID)
s.True(strings.HasSuffix(matched.GetAttributeValue().GetFqn(), fixtureAttrVal.Value))
s.True(strings.HasPrefix(matched.GetAttributeValue().GetFqn(), "https://"))
s.NotZero(matched.GetId())
s.NotNil(matched.GetActions())
}
Expand Down
10 changes: 8 additions & 2 deletions service/policy/db/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1244,18 +1244,24 @@ SELECT
'id', scs.id,
'subject_sets', scs.condition
) AS subject_condition_set,
JSON_BUILD_OBJECT('id', av.id,'value', av.value,'active', av.active) AS attribute_value
JSON_BUILD_OBJECT(
'id', av.id,
'value', av.value,
'active', av.active,
'fqn', fqns.fqn
) AS attribute_value
FROM subject_mappings sm
LEFT JOIN attribute_values av ON sm.attribute_value_id = av.id
LEFT JOIN attribute_definitions ad ON av.attribute_definition_id = ad.id
LEFT JOIN attribute_namespaces ns ON ad.namespace_id = ns.id
LEFT JOIN attribute_fqns fqns ON av.id = fqns.value_id
LEFT JOIN subject_condition_set scs ON scs.id = sm.subject_condition_set_id
WHERE ns.active = true AND ad.active = true and av.active = true AND EXISTS (
SELECT 1
FROM JSONB_ARRAY_ELEMENTS(scs.condition) AS ss, JSONB_ARRAY_ELEMENTS(ss->'conditionGroups') AS cg, JSONB_ARRAY_ELEMENTS(cg->'conditions') AS each_condition
WHERE (each_condition->>'subjectExternalSelectorValue' = ANY(@selectors::TEXT[]))
)
GROUP BY av.id, sm.id, scs.id;
GROUP BY av.id, sm.id, scs.id, fqns.fqn;

-- name: createSubjectMapping :one
WITH inserted_mapping AS (
Expand Down
20 changes: 16 additions & 4 deletions service/policy/db/query.sql.go

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

Loading