Skip to content

Commit f1be17d

Browse files
committed
remove duplicate test functions
Signed-off-by: Dmitry S <[email protected]>
1 parent ec1abdf commit f1be17d

File tree

1 file changed

+0
-242
lines changed

1 file changed

+0
-242
lines changed

test/e2e_test.go

Lines changed: 0 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"testing"
3939
"time"
4040

41-
"github.com/go-openapi/strfmt"
4241
"github.com/google/go-cmp/cmp"
4342
"github.com/google/go-containerregistry/pkg/name"
4443
"github.com/google/go-containerregistry/pkg/v1/remote"
@@ -1056,151 +1055,6 @@ func TestVerifyWithCARoots(t *testing.T) {
10561055
}
10571056
}
10581057

1059-
func TestAttachWithRFC3161Timestamp(t *testing.T) {
1060-
ctx := context.Background()
1061-
// TSA server needed to create timestamp
1062-
viper.Set("timestamp-signer", "memory")
1063-
viper.Set("timestamp-signer-hash", "sha256")
1064-
apiServer := server.NewRestAPIServer("localhost", 0, []string{"http"}, false, 10*time.Second, 10*time.Second)
1065-
server := httptest.NewServer(apiServer.GetHandler())
1066-
t.Cleanup(server.Close)
1067-
1068-
repo, stop := reg(t)
1069-
defer stop()
1070-
td := t.TempDir()
1071-
1072-
imgName := path.Join(repo, "cosign-attach-timestamp-e2e")
1073-
1074-
_, _, cleanup := mkimage(t, imgName)
1075-
defer cleanup()
1076-
1077-
b := bytes.Buffer{}
1078-
must(generate.GenerateCmd(context.Background(), options.RegistryOptions{}, imgName, nil, &b), t)
1079-
1080-
rootCert, rootKey, _ := GenerateRootCa()
1081-
subCert, subKey, _ := GenerateSubordinateCa(rootCert, rootKey)
1082-
leafCert, privKey, _ := GenerateLeafCert("[email protected]", "oidc-issuer", subCert, subKey)
1083-
pemRoot := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: rootCert.Raw})
1084-
pemSub := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: subCert.Raw})
1085-
pemLeaf := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: leafCert.Raw})
1086-
1087-
payloadref := mkfile(b.String(), td, t)
1088-
1089-
h := sha256.Sum256(b.Bytes())
1090-
signature, _ := privKey.Sign(rand.Reader, h[:], crypto.SHA256)
1091-
b64signature := base64.StdEncoding.EncodeToString([]byte(signature))
1092-
sigRef := mkfile(b64signature, td, t)
1093-
pemleafRef := mkfile(string(pemLeaf), td, t)
1094-
pemrootRef := mkfile(string(pemRoot), td, t)
1095-
1096-
certchainRef := mkfile(string(append(pemSub[:], pemRoot[:]...)), td, t)
1097-
1098-
t.Setenv("SIGSTORE_ROOT_FILE", pemrootRef)
1099-
// reset the roots to use the root pointed by the environment variable SIGSTORE_ROOT_FILE
1100-
if err := fulcioroots.ReInit(); err != nil {
1101-
t.Fatal(err)
1102-
}
1103-
1104-
tsclient, err := tsaclient.GetTimestampClient(server.URL)
1105-
if err != nil {
1106-
t.Error(err)
1107-
}
1108-
1109-
chain, err := tsclient.Timestamp.GetTimestampCertChain(nil)
1110-
if err != nil {
1111-
t.Fatalf("unexpected error getting timestamp chain: %v", err)
1112-
}
1113-
1114-
file, err := os.CreateTemp(os.TempDir(), "tempfile")
1115-
if err != nil {
1116-
t.Fatalf("error creating temp file: %v", err)
1117-
}
1118-
defer os.Remove(file.Name())
1119-
_, err = file.WriteString(chain.Payload)
1120-
if err != nil {
1121-
t.Fatalf("error writing chain payload to temp file: %v", err)
1122-
}
1123-
1124-
tsBytes, err := tsa.GetTimestampedSignature(signature, client.NewTSAClient(server.URL+"/api/v1/timestamp"))
1125-
if err != nil {
1126-
t.Fatalf("unexpected error creating timestamp: %v", err)
1127-
}
1128-
rfc3161TSRef := mkfile(string(tsBytes), td, t)
1129-
1130-
// Upload it!
1131-
err = attach.SignatureCmd(ctx, options.RegistryOptions{}, sigRef, payloadref, pemleafRef, certchainRef, rfc3161TSRef, "", imgName)
1132-
if err != nil {
1133-
t.Fatal(err)
1134-
}
1135-
1136-
must(verifyKeylessTSA(imgName, file.Name(), true, true), t)
1137-
}
1138-
1139-
func TestAttachWithRekorBundle(t *testing.T) {
1140-
ctx := context.Background()
1141-
1142-
repo, stop := reg(t)
1143-
defer stop()
1144-
td := t.TempDir()
1145-
1146-
imgName := path.Join(repo, "cosign-attach-timestamp-e2e")
1147-
1148-
_, _, cleanup := mkimage(t, imgName)
1149-
defer cleanup()
1150-
1151-
b := bytes.Buffer{}
1152-
must(generate.GenerateCmd(context.Background(), options.RegistryOptions{}, imgName, nil, &b), t)
1153-
1154-
rootCert, rootKey, _ := GenerateRootCa()
1155-
subCert, subKey, _ := GenerateSubordinateCa(rootCert, rootKey)
1156-
leafCert, privKey, _ := GenerateLeafCert("[email protected]", "oidc-issuer", subCert, subKey)
1157-
pemRoot := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: rootCert.Raw})
1158-
pemSub := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: subCert.Raw})
1159-
pemLeaf := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: leafCert.Raw})
1160-
1161-
payloadref := mkfile(b.String(), td, t)
1162-
1163-
h := sha256.Sum256(b.Bytes())
1164-
signature, _ := privKey.Sign(rand.Reader, h[:], crypto.SHA256)
1165-
b64signature := base64.StdEncoding.EncodeToString([]byte(signature))
1166-
sigRef := mkfile(b64signature, td, t)
1167-
pemleafRef := mkfile(string(pemLeaf), td, t)
1168-
pemrootRef := mkfile(string(pemRoot), td, t)
1169-
1170-
t.Setenv("SIGSTORE_ROOT_FILE", pemrootRef)
1171-
1172-
certchainRef := mkfile(string(append(pemSub[:], pemRoot[:]...)), td, t)
1173-
1174-
localPayload := cosign.LocalSignedPayload{
1175-
Base64Signature: b64signature,
1176-
Cert: string(pemLeaf),
1177-
Bundle: &bundle.RekorBundle{
1178-
SignedEntryTimestamp: strfmt.Base64("MEUCIEDcarEwRYkrxE9ne+kzEVvUhnWaauYzxhUyXOLy1hwAAiEA4VdVCvNRs+D/5o33C2KBy+q2YX3lP4Y7nqRFU+K3hi0="),
1179-
Payload: bundle.RekorPayload{
1180-
Body: "REMOVED",
1181-
IntegratedTime: 1631646761,
1182-
LogIndex: 693591,
1183-
LogID: "c0d23d6ad406973f9559f3ba2d1ca01f84147d8ffc5b8445c224f98b9591801d",
1184-
},
1185-
},
1186-
}
1187-
1188-
jsonBundle, err := json.Marshal(localPayload)
1189-
if err != nil {
1190-
t.Fatal(err)
1191-
}
1192-
bundlePath := filepath.Join(td, "bundle.json")
1193-
if err := os.WriteFile(bundlePath, jsonBundle, 0644); err != nil {
1194-
t.Fatal(err)
1195-
}
1196-
1197-
// Upload it!
1198-
err = attach.SignatureCmd(ctx, options.RegistryOptions{}, sigRef, payloadref, pemleafRef, certchainRef, "", bundlePath, imgName)
1199-
if err != nil {
1200-
t.Fatal(err)
1201-
}
1202-
}
1203-
12041058
func TestRekorBundle(t *testing.T) {
12051059
td := t.TempDir()
12061060
err := downloadAndSetEnv(t, rekorURL+"/api/v1/log/publicKey", env.VariableSigstoreRekorPublicKey.String(), td)
@@ -1832,102 +1686,6 @@ func TestGenerate(t *testing.T) {
18321686
equals(ss.Optional["foo"], "bar", t)
18331687
}
18341688

1835-
func TestUploadDownload(t *testing.T) {
1836-
repo, stop := reg(t)
1837-
defer stop()
1838-
td := t.TempDir()
1839-
ctx := context.Background()
1840-
1841-
testCases := map[string]struct {
1842-
signature string
1843-
signatureType attach.SignatureArgType
1844-
expectedErr bool
1845-
}{
1846-
"stdin containing signature": {
1847-
signature: "testsignatureraw",
1848-
signatureType: attach.StdinSignature,
1849-
expectedErr: false,
1850-
},
1851-
"file containing signature": {
1852-
signature: "testsignaturefile",
1853-
signatureType: attach.FileSignature,
1854-
expectedErr: false,
1855-
},
1856-
"raw signature as argument": {
1857-
signature: "testsignatureraw",
1858-
signatureType: attach.RawSignature,
1859-
expectedErr: true,
1860-
},
1861-
"empty signature as argument": {
1862-
signature: "",
1863-
signatureType: attach.RawSignature,
1864-
expectedErr: true,
1865-
},
1866-
}
1867-
1868-
imgName := path.Join(repo, "cosign-e2e")
1869-
for testName, testCase := range testCases {
1870-
t.Run(testName, func(t *testing.T) {
1871-
ref, _, cleanup := mkimage(t, imgName)
1872-
payload := "testpayload"
1873-
payloadPath := mkfile(payload, td, t)
1874-
signature := base64.StdEncoding.EncodeToString([]byte(testCase.signature))
1875-
restoreStdin := func() {}
1876-
1877-
var sigRef string
1878-
if testCase.signatureType == attach.FileSignature {
1879-
sigRef = mkfile(signature, td, t)
1880-
} else if testCase.signatureType == attach.StdinSignature {
1881-
sigRef = "-"
1882-
restoreStdin = mockStdin(signature, td, t)
1883-
} else {
1884-
sigRef = signature
1885-
}
1886-
// Upload it!
1887-
err := attach.SignatureCmd(ctx, options.RegistryOptions{}, sigRef, payloadPath, "", "", "", "", imgName)
1888-
if testCase.expectedErr {
1889-
mustErr(err, t)
1890-
} else {
1891-
must(err, t)
1892-
}
1893-
restoreStdin()
1894-
1895-
// Now download it!
1896-
se, err := ociremote.SignedEntity(ref, ociremote.WithRemoteOptions(registryClientOpts(ctx)...))
1897-
must(err, t)
1898-
sigs, err := se.Signatures()
1899-
must(err, t)
1900-
signatures, err := sigs.Get()
1901-
must(err, t)
1902-
1903-
if testCase.expectedErr {
1904-
if len(signatures) != 0 {
1905-
t.Fatalf("unexpected signatures %d, wanted 0", len(signatures))
1906-
}
1907-
} else {
1908-
if len(signatures) != 1 {
1909-
t.Fatalf("unexpected signatures %d, wanted 1", len(signatures))
1910-
}
1911-
1912-
if b64sig, err := signatures[0].Base64Signature(); err != nil {
1913-
t.Fatalf("Base64Signature() = %v", err)
1914-
} else if diff := cmp.Diff(b64sig, signature); diff != "" {
1915-
t.Error(diff)
1916-
}
1917-
1918-
if p, err := signatures[0].Payload(); err != nil {
1919-
t.Fatalf("Payload() = %v", err)
1920-
} else if diff := cmp.Diff(p, []byte(payload)); diff != "" {
1921-
t.Error(diff)
1922-
}
1923-
}
1924-
1925-
// Now delete it!
1926-
cleanup()
1927-
})
1928-
}
1929-
}
1930-
19311689
func TestSaveLoad(t *testing.T) {
19321690
td := t.TempDir()
19331691
err := downloadAndSetEnv(t, rekorURL+"/api/v1/log/publicKey", env.VariableSigstoreRekorPublicKey.String(), td)

0 commit comments

Comments
 (0)