@@ -52,7 +52,7 @@ import (
52
52
sreconcile "github.com/fluxcd/source-controller/internal/reconcile"
53
53
)
54
54
55
- const publicKeyFileName = "pub.pgp "
55
+ const publicKeyFileName = "pub.gpg "
56
56
57
57
func TestHelmChartReconciler_Reconcile (t * testing.T ) {
58
58
g := NewWithT (t )
@@ -458,14 +458,19 @@ func TestHelmChartReconciler_reconcileSource(t *testing.T) {
458
458
}
459
459
g .Expect (storage .Archive (gitArtifact , "testdata/charts" , nil )).To (Succeed ())
460
460
461
+ keyring , err := os .ReadFile ("testdata/charts/pub.gpg" )
462
+ g .Expect (err ).ToNot (HaveOccurred ())
463
+ g .Expect (keyring ).ToNot (BeEmpty ())
464
+
461
465
tests := []struct {
462
- name string
463
- source sourcev1.Source
464
- beforeFunc func (obj * sourcev1.HelmChart )
465
- want sreconcile.Result
466
- wantErr error
467
- assertFunc func (g * WithT , build chart.Build , obj sourcev1.HelmChart )
468
- cleanFunc func (g * WithT , build * chart.Build )
466
+ name string
467
+ source sourcev1.Source
468
+ keyringSecret * corev1.Secret
469
+ beforeFunc func (obj * sourcev1.HelmChart )
470
+ want sreconcile.Result
471
+ wantErr error
472
+ assertFunc func (g * WithT , build chart.Build , obj sourcev1.HelmChart )
473
+ cleanFunc func (g * WithT , build * chart.Build )
469
474
}{
470
475
{
471
476
name : "Observes Artifact revision and build result" ,
@@ -501,6 +506,59 @@ func TestHelmChartReconciler_reconcileSource(t *testing.T) {
501
506
g .Expect (os .Remove (build .Path )).To (Succeed ())
502
507
},
503
508
},
509
+ {
510
+ name : "Observes Artifact revision and build result with valid signature" ,
511
+ source : & sourcev1.GitRepository {
512
+ ObjectMeta : metav1.ObjectMeta {
513
+ Name : "gitrepository" ,
514
+ Namespace : "default" ,
515
+ },
516
+ Status : sourcev1.GitRepositoryStatus {
517
+ Artifact : gitArtifact ,
518
+ },
519
+ },
520
+ keyringSecret : & corev1.Secret {
521
+ ObjectMeta : metav1.ObjectMeta {
522
+ Name : "keyring-secret" ,
523
+ Namespace : "default" ,
524
+ },
525
+ Data : map [string ][]byte {
526
+ publicKeyFileName : keyring ,
527
+ },
528
+ },
529
+ beforeFunc : func (obj * sourcev1.HelmChart ) {
530
+ obj .Spec .Chart = "testdata/charts/helmchart-0.1.0.tgz"
531
+ obj .Spec .SourceRef = sourcev1.LocalHelmChartSourceReference {
532
+ Name : "gitrepository" ,
533
+ Kind : sourcev1 .GitRepositoryKind ,
534
+ }
535
+ obj .Spec .VerificationKeyring = & sourcev1.VerificationKeyring {
536
+ SecretRef : meta.LocalObjectReference {
537
+ Name : "keyring-secret" ,
538
+ },
539
+ Key : publicKeyFileName ,
540
+ }
541
+ },
542
+ want : sreconcile .ResultSuccess ,
543
+ assertFunc : func (g * WithT , build chart.Build , obj sourcev1.HelmChart ) {
544
+ g .Expect (build .Complete ()).To (BeTrue ())
545
+ g .Expect (build .Name ).To (Equal ("helmchart" ))
546
+ g .Expect (build .Version ).To (Equal ("0.1.0" ))
547
+ g .Expect (build .Path ).To (BeARegularFile ())
548
+ g .Expect (build .VerificationSignature ).ToNot (BeNil ())
549
+ g .Expect (build .ProvFilePath ).To (BeARegularFile ())
550
+
551
+ g .Expect (obj .Status .ObservedSourceArtifactRevision ).To (Equal (gitArtifact .Revision ))
552
+ g .Expect (obj .Status .Conditions ).To (conditions .MatchConditions ([]metav1.Condition {
553
+ * conditions .TrueCondition (sourcev1 .ArtifactOutdatedCondition , "NewChart" , "pulled 'helmchart' chart with version '0.1.0'" ),
554
+ * conditions .TrueCondition (sourcev1 .SourceVerifiedCondition , sourcev1 .ChartVerifiedSucceededReason , "chart signed by: TestUser using key with fingeprint: 943CB5929ECDA2B5B5EC88BC7035BA97D32A87C1 and hash verified: sha256:007c7b7446eebcb18caeffe9898a3356ba1795f54df40ad39cfcc7382874a10a" ),
555
+ }))
556
+ },
557
+ cleanFunc : func (g * WithT , build * chart.Build ) {
558
+ g .Expect (os .Remove (build .Path )).To (Succeed ())
559
+ g .Expect (os .Remove (build .ProvFilePath )).To (Succeed ())
560
+ },
561
+ },
504
562
{
505
563
name : "Error on unavailable source" ,
506
564
beforeFunc : func (obj * sourcev1.HelmChart ) {
@@ -605,6 +663,9 @@ func TestHelmChartReconciler_reconcileSource(t *testing.T) {
605
663
if tt .source != nil {
606
664
clientBuilder .WithRuntimeObjects (tt .source )
607
665
}
666
+ if tt .keyringSecret != nil {
667
+ clientBuilder .WithRuntimeObjects (tt .keyringSecret )
668
+ }
608
669
609
670
r := & HelmChartReconciler {
610
671
Client : clientBuilder .Build (),
@@ -1129,7 +1190,7 @@ func TestHelmChartReconciler_reconcileArtifact(t *testing.T) {
1129
1190
},
1130
1191
{
1131
1192
name : "Copying artifact to storage from build makes Ready=True" ,
1132
- build : mockChartBuild ("helmchart" , "0.1.0" , "testdata/charts/helmchart-0.1.0.tgz" , "" ),
1193
+ build : mockChartBuild ("helmchart" , "0.1.0" , "testdata/charts/helmchart-0.1.0.tgz" ),
1133
1194
beforeFunc : func (obj * sourcev1.HelmChart ) {
1134
1195
conditions .MarkTrue (obj , sourcev1 .ArtifactOutdatedCondition , "Foo" , "" )
1135
1196
},
@@ -1145,24 +1206,6 @@ func TestHelmChartReconciler_reconcileArtifact(t *testing.T) {
1145
1206
* conditions .TrueCondition (meta .ReadyCondition , sourcev1 .ChartPullSucceededReason , "pulled 'helmchart' chart with version '0.1.0'" ),
1146
1207
},
1147
1208
},
1148
- {
1149
- name : "Build with a verified signature sets SourceVerifiedCondition=Truue" ,
1150
- build : mockChartBuild ("helmchart" , "0.1.0" , "testdata/charts/helmchart-0.1.0.tgz" , "testdata/charts/helmchart-0.1.0.tgz.prov" ),
1151
- beforeFunc : func (obj * sourcev1.HelmChart ) {
1152
- obj .Status .Artifact = & sourcev1.Artifact {
1153
- Path : "testdata/charts/helmchart-0.1.0.tgz" ,
1154
- }
1155
- },
1156
- want : sreconcile .ResultSuccess ,
1157
- afterFunc : func (t * WithT , obj * sourcev1.HelmChart ) {
1158
- provArtifact := testStorage .NewArtifactFor (obj .Kind , obj .GetObjectMeta (), "0.1.0" , "helmchart-0.1.0.tgz.prov" )
1159
- t .Expect (provArtifact .Path ).ToNot (BeEmpty ())
1160
- },
1161
- assertConditions : []metav1.Condition {
1162
- * conditions .TrueCondition (meta .ReadyCondition , sourcev1 .ChartPullSucceededReason , "pulled 'helmchart' chart with version '0.1.0'" ),
1163
- * conditions .TrueCondition (sourcev1 .SourceVerifiedCondition , sourcev1 .ChartPullSucceededReason , "chart signed by: TestUser1,TestUser2 using key with fingeprint: 0102000000000000000000000000000000000000 and hash verified: 53gntj23r24asnf0" ),
1164
- },
1165
- },
1166
1209
{
1167
1210
name : "Up-to-date chart build does not persist artifact to storage" ,
1168
1211
build : & chart.Build {
@@ -1208,7 +1251,7 @@ func TestHelmChartReconciler_reconcileArtifact(t *testing.T) {
1208
1251
},
1209
1252
{
1210
1253
name : "Removes ArtifactOutdatedCondition after creating new artifact" ,
1211
- build : mockChartBuild ("helmchart" , "0.1.0" , "testdata/charts/helmchart-0.1.0.tgz" , "" ),
1254
+ build : mockChartBuild ("helmchart" , "0.1.0" , "testdata/charts/helmchart-0.1.0.tgz" ),
1212
1255
beforeFunc : func (obj * sourcev1.HelmChart ) {
1213
1256
conditions .MarkTrue (obj , sourcev1 .ArtifactOutdatedCondition , "Foo" , "" )
1214
1257
},
@@ -1226,7 +1269,7 @@ func TestHelmChartReconciler_reconcileArtifact(t *testing.T) {
1226
1269
},
1227
1270
{
1228
1271
name : "Creates latest symlink to the created artifact" ,
1229
- build : mockChartBuild ("helmchart" , "0.1.0" , "testdata/charts/helmchart-0.1.0.tgz" , "" ),
1272
+ build : mockChartBuild ("helmchart" , "0.1.0" , "testdata/charts/helmchart-0.1.0.tgz" ),
1230
1273
afterFunc : func (t * WithT , obj * sourcev1.HelmChart ) {
1231
1274
t .Expect (obj .GetArtifact ()).ToNot (BeNil ())
1232
1275
@@ -1726,10 +1769,8 @@ func TestHelmChartReconciler_reconcileSubRecs(t *testing.T) {
1726
1769
}
1727
1770
}
1728
1771
1729
- func mockChartBuild (name , version , path , provFilePath string ) * chart.Build {
1772
+ func mockChartBuild (name , version , path string ) * chart.Build {
1730
1773
var copyP string
1731
- var copyPP string
1732
- var verSig * chart.VerificationSignature
1733
1774
if path != "" {
1734
1775
f , err := os .Open (path )
1735
1776
if err == nil {
@@ -1743,29 +1784,9 @@ func mockChartBuild(name, version, path, provFilePath string) *chart.Build {
1743
1784
}
1744
1785
}
1745
1786
}
1746
- if provFilePath != "" {
1747
- f , err := os .Open (provFilePath )
1748
- if err == nil {
1749
- defer f .Close ()
1750
- ff , err := os .CreateTemp ("" , "chart-mock-*.tgz.prov" )
1751
- if err == nil {
1752
- defer ff .Close ()
1753
- if _ , err = io .Copy (ff , f ); err == nil {
1754
- copyPP = ff .Name ()
1755
- }
1756
- }
1757
- verSig = & chart.VerificationSignature {
1758
- FileHash : "53gntj23r24asnf0" ,
1759
- Identities : []string {"TestUser1" , "TestUser2" },
1760
- KeyFingerprint : [20 ]byte {1 , 2 },
1761
- }
1762
- }
1763
- }
1764
1787
return & chart.Build {
1765
- Name : name ,
1766
- Version : version ,
1767
- Path : copyP ,
1768
- ProvFilePath : copyPP ,
1769
- VerificationSignature : verSig ,
1788
+ Name : name ,
1789
+ Version : version ,
1790
+ Path : copyP ,
1770
1791
}
1771
1792
}
0 commit comments