Skip to content

Commit

Permalink
refactor: Remove depricated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lubux committed Dec 11, 2023
1 parent ae457d1 commit 0a030a3
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 292 deletions.
105 changes: 0 additions & 105 deletions openpgp/keys_v5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,89 +20,6 @@ func TestReadPrivateForeignV5Key(t *testing.T) {
}
}

// Deprecated
/*
// TODO: Replace message with a correctly generated one.
func testV5ForeignSignedMessage(t *testing.T) {
kring, err := ReadArmoredKeyRing(strings.NewReader(v5PrivKey))
if err != nil {
t.Fatal(err)
}
msg := strings.NewReader(v5PrivKeyMsg)
// Unarmor
block, err := armor.Decode(msg)
if err != nil {
return
}
md, err := ReadMessage(block.Body, kring, nil, nil)
if md.SignedBy == nil {
t.Fatal("incorrect signer")
}
if err != nil {
t.Fatal(err)
}
// Consume UnverifiedBody
body, err := ioutil.ReadAll(md.UnverifiedBody)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(body, []byte("test")) {
t.Fatal("bad body")
}
if md.SignatureError != nil {
t.Fatal(md.SignatureError)
}
if err != nil {
t.Fatal(err)
}
}
func TestReadPrivateEncryptedV5Key(t *testing.T) {
c := &packet.Config{V5Keys: true}
e, err := NewEntity("V5 Key Owner", "V5 Key", "[email protected]", c)
if err != nil {
t.Fatal(err)
}
password := []byte("test v5 key # password")
// Encrypt private key
if err = e.PrivateKey.Encrypt(password); err != nil {
t.Fatal(err)
}
// Encrypt subkeys
for _, sub := range e.Subkeys {
if err = sub.PrivateKey.Encrypt(password); err != nil {
t.Fatal(err)
}
}
// Serialize, Read
serializedEntity := bytes.NewBuffer(nil)
err = e.SerializePrivateWithoutSigning(serializedEntity, nil)
if err != nil {
t.Fatal(err)
}
el, err := ReadKeyRing(serializedEntity)
if err != nil {
t.Fatal(err)
}
// Decrypt
if el[0].PrivateKey == nil {
t.Fatal("No private key found")
}
if err = el[0].PrivateKey.Decrypt(password); err != nil {
t.Error(err)
}
// Decrypt subkeys
for _, sub := range e.Subkeys {
if err = sub.PrivateKey.Decrypt(password); err != nil {
t.Error(err)
}
}
checkV5Key(t, el[0])
}*/

func TestReadPrivateSerializeForeignV5Key(t *testing.T) {
for _, str := range foreignKeys {
el, err := ReadArmoredKeyRing(strings.NewReader(str))
Expand All @@ -113,28 +30,6 @@ func TestReadPrivateSerializeForeignV5Key(t *testing.T) {
}
}

// Deprecated
/*
func TestNewEntitySerializeV5Key(t *testing.T) {
c := &packet.Config{V5Keys: true}
e, err := NewEntity("V5 Key Owner", "V5 Key", "[email protected]", c)
if err != nil {
t.Fatal(err)
}
checkSerializeRead(t, e)
}
func TestNewEntityV5Key(t *testing.T) {
c := &packet.Config{
V5Keys: true,
}
e, err := NewEntity("V5 Key Owner", "V5 Key", "[email protected]", c)
if err != nil {
t.Fatal(err)
}
checkV5Key(t, e)
}*/

func checkV5Key(t *testing.T, ent *Entity) {
key := ent.PrimaryKey
if key.Version != 5 {
Expand Down
80 changes: 0 additions & 80 deletions openpgp/v2/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,67 +685,6 @@ func TestKeyWithSubKeyAndBadSelfSigOrder(t *testing.T) {

}

/*func TestKeyUsage(t *testing.T) {
kring, err := ReadKeyRing(readerFromHex(subkeyUsageHex))
if err != nil {
t.Fatal(err)
}
// subkeyUsageHex contains these keys:
// pub 1024R/2866382A created: 2014-04-01 expires: never usage: SC
// sub 1024R/936C9153 created: 2014-04-01 expires: never usage: E
// sub 1024R/64D5F5BB created: 2014-04-02 expires: never usage: E
// sub 1024D/BC0BA992 created: 2014-04-02 expires: never usage: S
certifiers := []uint64{0xA42704B92866382A}
signers := []uint64{0xA42704B92866382A, 0x42CE2C64BC0BA992}
encrypters := []uint64{0x09C0C7D9936C9153, 0xC104E98664D5F5BB}
for _, id := range certifiers {
keys := kring.KeysByIdUsage(id, packet.KeyFlagCertify)
if len(keys) == 1 {
if keys[0].PublicKey.KeyId != id {
t.Errorf("Expected to find certifier key id %X, but got %X", id, keys[0].PublicKey.KeyId)
}
} else {
t.Errorf("Expected one match for certifier key id %X, but got %d matches", id, len(keys))
}
}
for _, id := range signers {
keys := kring.KeysByIdUsage(id, packet.KeyFlagSign)
if len(keys) == 1 {
if keys[0].PublicKey.KeyId != id {
t.Errorf("Expected to find signing key id %X, but got %X", id, keys[0].PublicKey.KeyId)
}
} else {
t.Errorf("Expected one match for signing key id %X, but got %d matches", id, len(keys))
}
// This keyring contains no encryption keys that are also good for signing.
keys = kring.KeysByIdUsage(id, packet.KeyFlagEncryptStorage|packet.KeyFlagEncryptCommunications)
if len(keys) != 0 {
t.Errorf("Unexpected match for encryption key id %X", id)
}
}
for _, id := range encrypters {
keys := kring.KeysByIdUsage(id, packet.KeyFlagEncryptStorage|packet.KeyFlagEncryptCommunications)
if len(keys) == 1 {
if keys[0].PublicKey.KeyId != id {
t.Errorf("Expected to find encryption key id %X, but got %X", id, keys[0].PublicKey.KeyId)
}
} else {
t.Errorf("Expected one match for encryption key id %X, but got %d matches", id, len(keys))
}
// This keyring contains no encryption keys that are also good for signing.
keys = kring.KeysByIdUsage(id, packet.KeyFlagSign)
if len(keys) != 0 {
t.Errorf("Unexpected match for signing key id %X", id)
}
}
}*/

func TestIdVerification(t *testing.T) {
kring, err := ReadKeyRing(readerFromHex(testKeys1And2PrivateHex))
if err != nil {
Expand Down Expand Up @@ -1464,25 +1403,6 @@ func TestRevokeSubkey(t *testing.T) {
}
}

/*func TestRevokeSubkeyWithAnotherEntity(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", nil)
if err != nil {
t.Fatal(err)
}
sk := entity.Subkeys[0]
newEntity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", nil)
if err != nil {
t.Fatal(err)
}
err = newEntity.RevokeSubkey(&sk, packet.NoReason, "Key revocation", nil)
if err == nil {
t.Fatal("Entity was able to revoke a subkey owned by a different entity")
}
}*/

func TestRevokeSubkeyWithInvalidSignature(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", nil)
if err != nil {
Expand Down
107 changes: 0 additions & 107 deletions openpgp/v2/keys_v5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,91 +20,6 @@ func TestReadPrivateForeignV5Key(t *testing.T) {
}
}

// Deprecated
/*
func testV5ForeignSignedMessage(t *testing.T) {
kring, err := ReadArmoredKeyRing(strings.NewReader(v5PrivKey))
if err != nil {
t.Fatal(err)
}
msg := strings.NewReader(v5PrivKeyMsg)
// Unarmor
block, err := armor.Decode(msg)
if err != nil {
return
}
md, err := ReadMessage(block.Body, kring, nil, nil)
if len(md.SignatureCandidates) < 1 {
t.Fatal("no signature found")
}
if md.SignatureCandidates[0].SignedBy == nil {
t.Fatal("incorrect signer")
}
if err != nil {
t.Fatal(err)
}
// Consume UnverifiedBody
body, err := ioutil.ReadAll(md.UnverifiedBody)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(body, []byte("test")) {
t.Fatal("bad body")
}
if md.SignatureError != nil {
t.Fatal(md.SignatureError)
}
if err != nil {
t.Fatal(err)
}
}
func TestReadPrivateEncryptedV5Key(t *testing.T) {
c := &packet.Config{V5Keys: true}
e, err := NewEntity("V5 Key Owner", "V5 Key", "[email protected]", c)
if err != nil {
t.Fatal(err)
}
password := []byte("test v5 key # password")
// Encrypt private key
if err = e.PrivateKey.Encrypt(password); err != nil {
t.Fatal(err)
}
// Encrypt subkeys
for _, sub := range e.Subkeys {
if err = sub.PrivateKey.Encrypt(password); err != nil {
t.Fatal(err)
}
}
// Serialize, Read
serializedEntity := bytes.NewBuffer(nil)
err = e.SerializePrivateWithoutSigning(serializedEntity, nil)
if err != nil {
t.Fatal(err)
}
el, err := ReadKeyRing(serializedEntity)
if err != nil {
t.Fatal(err)
}
// Decrypt
if el[0].PrivateKey == nil {
t.Fatal("No private key found")
}
if err = el[0].PrivateKey.Decrypt(password); err != nil {
t.Error(err)
}
// Decrypt subkeys
for _, sub := range e.Subkeys {
if err = sub.PrivateKey.Decrypt(password); err != nil {
t.Error(err)
}
}
checkV5Key(t, el[0])
}*/

func TestReadPrivateSerializeForeignV5Key(t *testing.T) {
for _, str := range foreignKeys {
el, err := ReadArmoredKeyRing(strings.NewReader(str))
Expand All @@ -115,28 +30,6 @@ func TestReadPrivateSerializeForeignV5Key(t *testing.T) {
}
}

// Deprecated
/*
func TestNewEntitySerializeV5Key(t *testing.T) {
c := &packet.Config{V5Keys: true}
e, err := NewEntity("V5 Key Owner", "V5 Key", "[email protected]", c)
if err != nil {
t.Fatal(err)
}
checkSerializeRead(t, e)
}
func TestNewEntityV5Key(t *testing.T) {
c := &packet.Config{
V5Keys: true,
}
e, err := NewEntity("V5 Key Owner", "V5 Key", "[email protected]", c)
if err != nil {
t.Fatal(err)
}
checkV5Key(t, e)
}*/

func checkV5Key(t *testing.T, ent *Entity) {
key := ent.PrimaryKey
if key.Version != 5 {
Expand Down

0 comments on commit 0a030a3

Please sign in to comment.