Skip to content

Commit 35c997b

Browse files
committed
handle cached artifactory manifests
1 parent f8b3714 commit 35c997b

File tree

5 files changed

+59
-20
lines changed

5 files changed

+59
-20
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
- name: golangci-lint
3434
uses: golangci/golangci-lint-action@v6.1.1
3535
with:
36-
version: v1.60.0
36+
version: v1.58.0

storage/signature.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
var _ Storage = (*Signature)(nil)
1818

1919
const (
20-
sigzipFilename = "extension.sigzip"
20+
SigzipFilename = "extension.sigzip"
2121
sigManifestName = ".signature.manifest"
2222
)
2323

@@ -67,17 +67,24 @@ func (s *Signature) Manifest(ctx context.Context, publisher, name string, versio
6767
}
6868

6969
if s.SigningEnabled() {
70+
for _, asset := range manifest.Assets.Asset {
71+
if asset.Path == SigzipFilename {
72+
// Already signed
73+
return manifest, nil
74+
}
75+
}
7076
manifest.Assets.Asset = append(manifest.Assets.Asset, VSIXAsset{
7177
Type: VSIXSignatureType,
72-
Path: sigzipFilename,
78+
Path: SigzipFilename,
7379
Addressable: "true",
7480
})
81+
return manifest, nil
7582
}
7683
return manifest, nil
7784
}
7885

7986
// Open will intercept requests for signed extensions payload.
80-
// It does this by looking for 'sigzipFilename' or p7s.sig.
87+
// It does this by looking for 'SigzipFilename' or p7s.sig.
8188
//
8289
// The signed payload and signing process is taken from:
8390
// https://github.com/filiptronicek/node-ovsx-sign
@@ -98,7 +105,7 @@ func (s *Signature) Manifest(ctx context.Context, publisher, name string, versio
98105
// source implementation. Ideally this marketplace would match Microsoft's
99106
// marketplace API.
100107
func (s *Signature) Open(ctx context.Context, fp string) (fs.File, error) {
101-
if s.SigningEnabled() && filepath.Base(fp) == sigzipFilename {
108+
if s.SigningEnabled() && filepath.Base(fp) == SigzipFilename {
102109
// hijack this request, sign the sig manifest
103110
manifest, err := s.Storage.Open(ctx, filepath.Join(filepath.Dir(fp), sigManifestName))
104111
if err != nil {
@@ -119,7 +126,7 @@ func (s *Signature) Open(ctx context.Context, fp string) (fs.File, error) {
119126
return nil, xerrors.Errorf("sign and zip manifest: %w", err)
120127
}
121128

122-
f := mem.NewFileHandle(mem.CreateFile(sigzipFilename))
129+
f := mem.NewFileHandle(mem.CreateFile(SigzipFilename))
123130
_, err = f.Write(signed)
124131
return f, err
125132
}

storage/signature_test.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
package storage_test
22

33
import (
4+
"crypto"
45
"testing"
56

67
"github.com/coder/code-marketplace/extensionsign"
78
"github.com/coder/code-marketplace/storage"
89
)
910

10-
func signed(factory func(t *testing.T) testStorage) func(t *testing.T) testStorage {
11+
func expectSignature(manifest *storage.VSIXManifest) {
12+
manifest.Assets.Asset = append(manifest.Assets.Asset, storage.VSIXAsset{
13+
Type: storage.VSIXSignatureType,
14+
Path: storage.SigzipFilename,
15+
Addressable: "true",
16+
})
17+
}
18+
19+
//nolint:revive // test control flag
20+
func signed(signer bool, factory func(t *testing.T) testStorage) func(t *testing.T) testStorage {
1121
return func(t *testing.T) testStorage {
1222
st := factory(t)
13-
key, _ := extensionsign.GenerateKey()
23+
var key crypto.Signer
24+
var exp func(*storage.VSIXManifest)
25+
if signer {
26+
key, _ = extensionsign.GenerateKey()
27+
exp = expectSignature
28+
}
1429

1530
return testStorage{
16-
storage: storage.NewSignatureStorage(key, st.storage),
17-
write: st.write,
18-
exists: st.exists,
31+
storage: storage.NewSignatureStorage(key, st.storage),
32+
write: st.write,
33+
exists: st.exists,
34+
expectedManifest: exp,
1935
}
2036
}
2137
}

storage/storage_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strconv"
1616
"testing"
1717

18+
"github.com/stretchr/testify/assert"
1819
"github.com/stretchr/testify/require"
1920

2021
"github.com/coder/code-marketplace/storage"
@@ -25,6 +26,8 @@ type testStorage struct {
2526
storage storage.Storage
2627
write func(content []byte, elem ...string)
2728
exists func(elem ...string) bool
29+
30+
expectedManifest func(man *storage.VSIXManifest)
2831
}
2932
type storageFactory = func(t *testing.T) testStorage
3033

@@ -132,14 +135,14 @@ func TestStorage(t *testing.T) {
132135
name: "Artifactory",
133136
factory: artifactoryFactory,
134137
},
135-
//{
136-
// name: "SignedLocal",
137-
// factory: signed(localFactory),
138-
//},
139-
//{
140-
// name: "SignedArtifactory",
141-
// factory: signed(artifactoryFactory),
142-
//},
138+
{
139+
name: "SignedLocal",
140+
factory: signed(true, localFactory),
141+
},
142+
{
143+
name: "SignedArtifactory",
144+
factory: signed(true, artifactoryFactory),
145+
},
143146
}
144147
for _, sf := range factories {
145148
t.Run(sf.name, func(t *testing.T) {
@@ -332,7 +335,12 @@ func testManifest(t *testing.T, factory storageFactory) {
332335
Path: fmt.Sprintf("%s.%s-%s.vsix", test.extension.Publisher, test.extension.Name, test.version),
333336
Addressable: "true",
334337
})
335-
require.Equal(t, test.expected, manifest)
338+
if f.expectedManifest != nil {
339+
f.expectedManifest(test.expected)
340+
}
341+
if !assert.Equal(t, test.expected, manifest) {
342+
fmt.Println("Asd")
343+
}
336344
}
337345
})
338346
}

testutil/extensions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ type Extension struct {
2626
Pack []string
2727
}
2828

29+
func (e Extension) Copy() Extension {
30+
var n Extension
31+
data, _ := json.Marshal(e)
32+
_ = json.Unmarshal(data, &n)
33+
return n
34+
}
35+
2936
var Extensions = []Extension{
3037
{
3138
Publisher: "foo",
@@ -113,6 +120,7 @@ var Extensions = []Extension{
113120
}
114121

115122
func ConvertExtensionToManifest(ext Extension, version storage.Version) *storage.VSIXManifest {
123+
ext = ext.Copy()
116124
return &storage.VSIXManifest{
117125
Metadata: storage.VSIXMetadata{
118126
Identity: storage.VSIXIdentity{

0 commit comments

Comments
 (0)