@ -406,6 +406,97 @@ func TestVerify(t *testing.T) {
}
}
func TestMarshalMetadataFlowStyle ( t * testing . T ) {
meta := map [ string ] any {
"name" : "test-chart" ,
"version" : "1.0.0" ,
"keywords" : [ ] string { "foo" , "bar" } ,
"sources" : [ ] string { "https://example.com" } ,
}
out , err := MarshalMetadata ( meta )
if err != nil {
t . Fatal ( err )
}
result := string ( out )
// Flow style means arrays are inline
if ! strings . Contains ( result , "[foo, bar]" ) {
t . Errorf ( "expected flow-style keywords, got:\n%s" , result )
}
// No line should start with "-" which is what triggers PGP dash-escaping
for line := range strings . SplitSeq ( result , "\n" ) {
if strings . HasPrefix ( line , "-" ) {
t . Errorf ( "found line starting with '-' which will cause PGP dash-escaping: %q" , line )
}
}
}
func TestMarshalMetadataRoundTrip ( t * testing . T ) {
type Meta struct {
Name string ` json:"name" `
Keywords [ ] string ` json:"keywords" `
Sources [ ] string ` json:"sources" `
}
original := Meta {
Name : "test-chart" ,
Keywords : [ ] string { "foo" , "bar" } ,
Sources : [ ] string { "https://example.com" , "https://example.org" } ,
}
out , err := MarshalMetadata ( original )
if err != nil {
t . Fatal ( err )
}
// Unmarshal metadataBytes back directly — not from disk
var restored Meta
if err := yaml . Unmarshal ( out , & restored ) ; err != nil {
t . Fatalf ( "failed to unmarshal metadataBytes back: %v" , err )
}
assert . Equal ( t , original . Keywords , restored . Keywords , "keywords should survive round-trip" )
assert . Equal ( t , original . Sources , restored . Sources , "sources should survive round-trip" )
}
func TestClearSignNoDashEscaping ( t * testing . T ) {
signer , err := NewFromFiles ( testKeyfile , testPubfile )
if err != nil {
t . Fatal ( err )
}
// Build metadata with keywords and sources — the fields that trigger the bug
meta := map [ string ] any {
"name" : "hashtest" ,
"version" : "1.2.3" ,
"keywords" : [ ] string { "foo" , "bar" } ,
"sources" : [ ] string { "https://example.com" } ,
}
metadataBytes , err := MarshalMetadata ( meta )
if err != nil {
t . Fatal ( err )
}
archiveData , err := os . ReadFile ( testChartfile )
if err != nil {
t . Fatal ( err )
}
// Run through the FULL signing pipeline
sig , err := signer . ClearSign ( archiveData , filepath . Base ( testChartfile ) , metadataBytes )
if err != nil {
t . Fatal ( err )
}
if strings . Contains ( sig , "- - " ) {
t . Errorf ( "prov file contains PGP dash-escaped list items '- - ', meaning flow style fix isn't working:\n%s" , sig )
}
}
// readSumFile reads a file containing a sum generated by the UNIX shasum tool.
func readSumFile ( sumfile string ) ( string , error ) {
data , err := os . ReadFile ( sumfile )