@@ -469,9 +469,14 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_Definition
469
469
s .Contains (grantIDs , got .GetGrants ()[1 ].GetId ())
470
470
pemIsPresent := false
471
471
472
- for i , g := range got .GetGrants () {
472
+ for _ , g := range got .GetGrants () {
473
473
if g .GetId () == key2 .KeyAccessServerID {
474
- s .Equal (base64 .StdEncoding .EncodeToString ([]byte (g .GetPublicKey ().GetCached ().GetKeys ()[i ].GetPem ())), key2 .PublicKeyCtx )
474
+ decodedPubKey , err := base64 .StdEncoding .DecodeString (key2 .PublicKeyCtx )
475
+ s .Require ().NoError (err )
476
+ s .Equal (
477
+ strings .TrimRight (string (decodedPubKey ), "\n " ),
478
+ fmt .Sprintf ("{\" pem\" :\" %s\" }" , base64 .StdEncoding .EncodeToString ([]byte (g .GetPublicKey ().GetCached ().GetKeys ()[0 ].GetPem ()))),
479
+ )
475
480
s .Equal (g .GetId (), key2 .KeyAccessServerID )
476
481
pemIsPresent = true
477
482
}
@@ -541,16 +546,6 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_Values() {
541
546
s .Empty (got .GetGrants ())
542
547
s .Empty (got .GetValues ()[0 ].GetGrants ())
543
548
544
- // create a new kas registration
545
- remoteKASName := "testing-io-remote"
546
- remoteKAS , err := s .db .PolicyClient .CreateKeyAccessServer (s .ctx , & kasregistry.CreateKeyAccessServerRequest {
547
- Uri : "https://testing.io/kas" ,
548
- PublicKey : & policy.PublicKey {},
549
- Name : remoteKASName ,
550
- })
551
- s .Require ().NoError (err )
552
- s .NotNil (remoteKAS )
553
-
554
549
// make a grant association to the first value
555
550
grant , err := s .db .PolicyClient .AssignPublicKeyToValue (s .ctx , & attributes.ValueKey {
556
551
KeyId : key .ID ,
@@ -559,16 +554,6 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_Values() {
559
554
s .Require ().NoError (err )
560
555
s .NotNil (grant )
561
556
562
- // create a second kas registration and grant it to the second value
563
- cachedKASName := "testion-io-local"
564
- cachedKAS , err := s .db .PolicyClient .CreateKeyAccessServer (s .ctx , & kasregistry.CreateKeyAccessServerRequest {
565
- Uri : "https://testing.io/kas2" ,
566
- PublicKey : & policy.PublicKey {},
567
- Name : cachedKASName ,
568
- })
569
- s .Require ().NoError (err )
570
- s .NotNil (cachedKAS )
571
-
572
557
grant2 , err := s .db .PolicyClient .AssignPublicKeyToValue (s .ctx , & attributes.ValueKey {
573
558
KeyId : key2 .ID ,
574
559
ValueId : valueSecond .GetId (),
@@ -597,11 +582,9 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_Values() {
597
582
firstGrant := grants [0 ]
598
583
switch v .GetId () {
599
584
case valueFirst .GetId ():
600
- s .Equal (remoteKAS .GetId (), firstGrant .GetId ())
601
- s .Equal (remoteKASName , firstGrant .GetName ())
585
+ s .Equal (key .KeyAccessServerID , firstGrant .GetId ())
602
586
case valueSecond .GetId ():
603
- s .Equal (cachedKAS .GetId (), firstGrant .GetId ())
604
- s .Equal (cachedKASName , firstGrant .GetName ())
587
+ s .Equal (key2 .KeyAccessServerID , firstGrant .GetId ())
605
588
default :
606
589
s .Fail ("unexpected value" , v )
607
590
}
@@ -652,14 +635,6 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_DefAndValu
652
635
s .Empty (got .GetGrants ())
653
636
s .Empty (got .GetValues ()[0 ].GetGrants ())
654
637
655
- // create a new kas registration
656
- valKAS1 , err := s .db .PolicyClient .CreateKeyAccessServer (s .ctx , & kasregistry.CreateKeyAccessServerRequest {
657
- Uri : "https://testing.org/kas" ,
658
- PublicKey : & policy.PublicKey {},
659
- })
660
- s .Require ().NoError (err )
661
- s .NotNil (valKAS1 )
662
-
663
638
// make a grant association to the first value
664
639
grant , err := s .db .PolicyClient .AssignPublicKeyToValue (s .ctx , & attributes.ValueKey {
665
640
KeyId : key .ID ,
@@ -668,29 +643,13 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_DefAndValu
668
643
s .Require ().NoError (err )
669
644
s .NotNil (grant )
670
645
671
- // create a second kas registration and grant it to the second value
672
- valKAS2 , err := s .db .PolicyClient .CreateKeyAccessServer (s .ctx , & kasregistry.CreateKeyAccessServerRequest {
673
- Uri : "https://testing.org/kas2" ,
674
- PublicKey : & policy.PublicKey {},
675
- })
676
- s .Require ().NoError (err )
677
- s .NotNil (valKAS2 )
678
-
679
646
grant2 , err := s .db .PolicyClient .AssignPublicKeyToValue (s .ctx , & attributes.ValueKey {
680
647
KeyId : key2 .ID ,
681
648
ValueId : valueSecond .GetId (),
682
649
})
683
650
s .Require ().NoError (err )
684
651
s .NotNil (grant2 )
685
652
686
- // create a third kas registration and grant it to the attribute definition
687
- defKAS , err := s .db .PolicyClient .CreateKeyAccessServer (s .ctx , & kasregistry.CreateKeyAccessServerRequest {
688
- Uri : "https://testing.org/kas3" ,
689
- PublicKey : & policy.PublicKey {},
690
- })
691
- s .Require ().NoError (err )
692
- s .NotNil (defKAS )
693
-
694
653
defGrant , err := s .db .PolicyClient .AssignPublicKeyToAttribute (s .ctx , & attributes.AttributeKey {
695
654
KeyId : key3 .ID ,
696
655
AttributeId : a .GetId (),
@@ -705,24 +664,24 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_DefAndValu
705
664
706
665
// ensure the attribute has exactly one definition grant
707
666
s .Len (got .GetGrants (), 1 )
708
- s .Equal (defKAS . GetId () , got .GetGrants ()[0 ].GetId ())
667
+ s .Equal (key3 . KeyAccessServerID , got .GetGrants ()[0 ].GetId ())
709
668
710
669
// get the attribute by the fqn of one of its values and ensure the grants are present
711
670
got , err = s .db .PolicyClient .GetAttributeByFqn (s .ctx , val1Fqn )
712
671
s .Require ().NoError (err )
713
672
s .NotNil (got )
714
673
s .Len (got .GetValues (), 2 )
715
674
s .Len (got .GetGrants (), 1 )
716
- s .Equal (defKAS . GetId () , got .GetGrants ()[0 ].GetId ())
675
+ s .Equal (key . KeyAccessServerID , got .GetGrants ()[0 ].GetId ())
717
676
718
677
for _ , v := range got .GetValues () {
719
678
switch v .GetId () {
720
679
case valueFirst .GetId ():
721
680
s .Require ().Len (v .GetGrants (), 1 )
722
- s .Equal (valKAS1 . GetId () , v .GetGrants ()[0 ].GetId ())
681
+ s .Equal (key . KeyAccessServerID , v .GetGrants ()[0 ].GetId ())
723
682
case valueSecond .GetId ():
724
683
s .Require ().Len (v .GetGrants (), 1 )
725
- s .Equal (valKAS2 . GetId () , v .GetGrants ()[0 ].GetId ())
684
+ s .Equal (key2 . KeyAccessServerID , v .GetGrants ()[0 ].GetId ())
726
685
default :
727
686
s .Fail ("unexpected value" , v )
728
687
}
@@ -748,16 +707,6 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_NamespaceG
748
707
s .Require ().NoError (err )
749
708
s .NotNil (attr )
750
709
751
- // create a new kas registration
752
- nsKASName := "namespace-kas1"
753
- kas , err := s .db .PolicyClient .CreateKeyAccessServer (s .ctx , & kasregistry.CreateKeyAccessServerRequest {
754
- Uri : "https://testing_granted_namespace.com/kas" ,
755
- PublicKey : & policy.PublicKey {},
756
- Name : nsKASName ,
757
- })
758
- s .Require ().NoError (err )
759
- s .NotNil (kas )
760
-
761
710
// make a grant association to the namespace
762
711
grant , err := s .db .PolicyClient .AssignPublicKeyToNamespace (s .ctx , & namespaces.NamespaceKey {
763
712
KeyId : key .ID ,
@@ -775,20 +724,25 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_NamespaceG
775
724
gotNs := got .GetNamespace ()
776
725
grants := gotNs .GetGrants ()
777
726
s .Len (grants , 1 )
778
- s .Equal (kas .GetId (), grants [0 ].GetId ())
779
- s .Equal (nsKASName , grants [0 ].GetName ())
727
+ s .Equal (key .KeyAccessServerID , grants [0 ].GetId ())
780
728
}
781
729
782
730
// for all the big tests set up:
783
731
// attribute name is "test_attr", values are "value1" and "value2"
784
732
// kas uris granted to each are "https://testing_granted_<ns | attr | val1 | val1>.com/<ns>/kas",
733
+ type KasAssociations struct {
734
+ kasID string
735
+ uri string
736
+ keyID string
737
+ keyUUID string
738
+ }
785
739
type bigSetup struct {
786
740
attrFqn string
787
741
nsID string
788
742
attrID string
789
743
val1ID string
790
744
val2ID string
791
- kasAssociations map [string ]string
745
+ kasAssociations map [string ]* KasAssociations
792
746
}
793
747
794
748
func (s * AttributeFqnSuite ) TestGetAttributeByFqn_SameResultsWhetherAttrOrValueFqnUsed () {
@@ -846,53 +800,53 @@ func (s *AttributeFqnSuite) TestGetAttributeByFqn_WithKeyAccessGrants_ProperOnAl
846
800
// ensure the namespace has the grants
847
801
s .Len (got .GetNamespace ().GetGrants (), 1 )
848
802
nsGrant := got .GetNamespace ().GetGrants ()[0 ]
849
- s .Equal (setup .kasAssociations [got .GetNamespace ().GetId ()], nsGrant .GetId ())
803
+ s .Equal (setup .kasAssociations [got .GetNamespace ().GetId ()]. kasID , nsGrant .GetId ())
850
804
s .Equal (fmt .Sprintf ("https://testing_granted_ns.com/%s/kas" , ns ), nsGrant .GetUri ())
851
805
852
806
// ensure the attribute has the grants
853
807
s .Len (got .GetGrants (), 1 )
854
808
attrGrant := got .GetGrants ()[0 ]
855
- s .Equal (setup .kasAssociations [got .GetId ()], attrGrant .GetId ())
809
+ s .Equal (setup .kasAssociations [got .GetId ()]. kasID , attrGrant .GetId ())
856
810
s .Equal (fmt .Sprintf ("https://testing_granted_attr.com/%s/kas" , ns ), attrGrant .GetUri ())
857
811
858
812
// ensure the first value has the grants
859
813
val1 := got .GetValues ()[0 ]
860
814
s .Len (val1 .GetGrants (), 1 )
861
815
val1Grant := val1 .GetGrants ()[0 ]
862
- s .Equal (setup .kasAssociations [val1 .GetId ()], val1Grant .GetId ())
816
+ s .Equal (setup .kasAssociations [val1 .GetId ()]. kasID , val1Grant .GetId ())
863
817
s .Equal (fmt .Sprintf ("https://testing_granted_val.com/%s/kas" , ns ), val1Grant .GetUri ())
864
818
865
819
// ensure the second value has the grants
866
820
val2 := got .GetValues ()[1 ]
867
821
s .Len (val2 .GetGrants (), 1 )
868
822
val2Grant := val2 .GetGrants ()[0 ]
869
- s .Equal (setup .kasAssociations [val2 .GetId ()], val2Grant .GetId ())
823
+ s .Equal (setup .kasAssociations [val2 .GetId ()]. kasID , val2Grant .GetId ())
870
824
s .Equal (fmt .Sprintf ("https://testing_granted_val2.com/%s/kas" , ns ), val2Grant .GetUri ())
871
825
872
826
// remove grants from all objects
873
- // _, err = s.db.PolicyClient.RemoveKeyAccessServerFromNamespace (s.ctx, &namespaces.NamespaceKeyAccessServer {
874
- // KeyAccessServerId: nsGrant. GetId(),
875
- // NamespaceId: got.GetNamespace().GetId(),
876
- // })
877
- // s.Require().NoError(err)
878
-
879
- // _, err = s.db.PolicyClient.RemoveKeyAccessServerFromAttribute (s.ctx, &attributes.AttributeKeyAccessServer {
880
- // KeyAccessServerId: attrGrant. GetId(),
881
- // AttributeId: got.GetId(),
882
- // })
883
- // s.Require().NoError(err)
884
-
885
- // _, err = s.db.PolicyClient.RemoveKeyAccessServerFromValue (s.ctx, &attributes.ValueKeyAccessServer {
886
- // KeyAccessServerId: val1Grant. GetId(),
887
- // ValueId: val1.GetId(),
888
- // })
889
- // s.Require().NoError(err)
890
-
891
- // _, err = s.db.PolicyClient.RemoveKeyAccessServerFromValue (s.ctx, &attributes.ValueKeyAccessServer {
892
- // KeyAccessServerId: val2Grant. GetId(),
893
- // ValueId: val2.GetId(),
894
- // })
895
- // s.Require().NoError(err)
827
+ _ , err = s .db .PolicyClient .RemovePublicKeyFromNamespace (s .ctx , & namespaces.NamespaceKey {
828
+ KeyId : setup . kasAssociations [ got . GetNamespace (). GetId ()]. keyUUID ,
829
+ NamespaceId : got .GetNamespace ().GetId (),
830
+ })
831
+ s .Require ().NoError (err )
832
+
833
+ _ , err = s .db .PolicyClient .RemovePublicKeyFromAttribute (s .ctx , & attributes.AttributeKey {
834
+ KeyId : setup . kasAssociations [ got . GetId ()]. keyUUID ,
835
+ AttributeId : got .GetId (),
836
+ })
837
+ s .Require ().NoError (err )
838
+
839
+ _ , err = s .db .PolicyClient .RemovePublicKeyFromValue (s .ctx , & attributes.ValueKey {
840
+ KeyId : setup . kasAssociations [ val1 . GetId ()]. keyUUID ,
841
+ ValueId : val1 .GetId (),
842
+ })
843
+ s .Require ().NoError (err )
844
+
845
+ _ , err = s .db .PolicyClient .RemovePublicKeyFromValue (s .ctx , & attributes.ValueKey {
846
+ KeyId : setup . kasAssociations [ val2 . GetId ()]. keyUUID ,
847
+ ValueId : val2 .GetId (),
848
+ })
849
+ s .Require ().NoError (err )
896
850
897
851
// ensure the grants are removed from all objects
898
852
got , err = s .db .PolicyClient .GetAttributeByFqn (s .ctx , setup .attrFqn )
@@ -1684,7 +1638,7 @@ func (s *AttributeFqnSuite) bigTestSetup(namespaceName string) bigSetup {
1684
1638
val1KasURI := fmt .Sprintf ("https://testing_granted_val.com/%s/kas" , namespaceName )
1685
1639
val2KasURI := fmt .Sprintf ("https://testing_granted_val2.com/%s/kas" , namespaceName )
1686
1640
1687
- kasAssociations := map [string ]string {}
1641
+ kasAssociations := map [string ]* KasAssociations {}
1688
1642
// create new KASes
1689
1643
for _ , toAssociate := range []struct {
1690
1644
id string
@@ -1720,36 +1674,41 @@ func (s *AttributeFqnSuite) bigTestSetup(namespaceName string) bigSetup {
1720
1674
s .Require ().NoError (err )
1721
1675
s .NotNil (resp )
1722
1676
1723
- kasAssociations [toAssociate .id ] = resp .GetKasKey ().GetKey ().GetId ()
1677
+ kasAssociations [toAssociate .id ] = & KasAssociations {
1678
+ kasID : kas .GetId (),
1679
+ uri : toAssociate .uri ,
1680
+ keyID : resp .GetKasKey ().GetKey ().GetKeyId (),
1681
+ keyUUID : resp .GetKasKey ().GetKey ().GetId (),
1682
+ }
1724
1683
}
1725
1684
1726
1685
// make a grant association to the namespace
1727
1686
nsGrant , err := s .db .PolicyClient .AssignPublicKeyToNamespace (s .ctx , & namespaces.NamespaceKey {
1728
- KeyId : kasAssociations [ns .GetId ()],
1687
+ KeyId : kasAssociations [ns .GetId ()]. keyUUID ,
1729
1688
NamespaceId : ns .GetId (),
1730
1689
})
1731
1690
s .Require ().NoError (err )
1732
1691
s .NotNil (nsGrant )
1733
1692
1734
1693
// make a grant association to the attribute definition
1735
1694
attrGrant , err := s .db .PolicyClient .AssignPublicKeyToAttribute (s .ctx , & attributes.AttributeKey {
1736
- KeyId : kasAssociations [attr .GetId ()],
1695
+ KeyId : kasAssociations [attr .GetId ()]. keyUUID ,
1737
1696
AttributeId : attr .GetId (),
1738
1697
})
1739
1698
s .Require ().NoError (err )
1740
1699
s .NotNil (attrGrant )
1741
1700
1742
1701
// make a grant association to the first value
1743
1702
val1Grant , err := s .db .PolicyClient .AssignPublicKeyToValue (s .ctx , & attributes.ValueKey {
1744
- KeyId : kasAssociations [val1 .GetId ()],
1703
+ KeyId : kasAssociations [val1 .GetId ()]. keyUUID ,
1745
1704
ValueId : val1 .GetId (),
1746
1705
})
1747
1706
s .Require ().NoError (err )
1748
1707
s .NotNil (val1Grant )
1749
1708
1750
1709
// make a grant association to the second value
1751
1710
val2Grant , err := s .db .PolicyClient .AssignPublicKeyToValue (s .ctx , & attributes.ValueKey {
1752
- KeyId : kasAssociations [val2 .GetId ()],
1711
+ KeyId : kasAssociations [val2 .GetId ()]. keyUUID ,
1753
1712
ValueId : val2 .GetId (),
1754
1713
})
1755
1714
s .Require ().NoError (err )
0 commit comments