mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-01-07 02:17:57 +01:00
Add junit test and fix checkstyle issues
This commit is contained in:
parent
e87ea6c8f4
commit
a6fb30668e
8 changed files with 129 additions and 7 deletions
|
@ -76,7 +76,7 @@ public class DiscoverInfoProvider extends IQProvider<DiscoverInfo> {
|
|||
if (parser.getName().equals("feature")) {
|
||||
// Create a new feature and add it to the discovered info.
|
||||
boolean notADuplicateFeature = discoverInfo.addFeature(variable);
|
||||
assert (notADuplicateFeature);
|
||||
// assert (notADuplicateFeature);
|
||||
}
|
||||
if (parser.getName().equals("query")) {
|
||||
done = true;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.openpgp;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.ox.bouncycastle;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
@ -13,7 +29,6 @@ import java.util.Collections;
|
|||
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint;
|
||||
import org.jivesoftware.smackx.ox.SecretKeyBackupHelper;
|
||||
import org.jivesoftware.smackx.ox.element.SecretkeyElement;
|
||||
import org.jivesoftware.smackx.ox.exception.InvalidBackupCodeException;
|
||||
import org.jivesoftware.smackx.ox.exception.MissingOpenPgpKeyPairException;
|
||||
|
@ -21,6 +36,7 @@ import org.jivesoftware.smackx.ox.exception.MissingOpenPgpPublicKeyException;
|
|||
import org.jivesoftware.smackx.ox.exception.MissingUserIdOnKeyException;
|
||||
import org.jivesoftware.smackx.ox.exception.SmackOpenPgpException;
|
||||
import org.jivesoftware.smackx.ox.util.KeyBytesAndFingerprint;
|
||||
import org.jivesoftware.smackx.ox.util.SecretKeyBackupHelper;
|
||||
|
||||
import de.vanitasvitae.crypto.pgpainless.key.UnprotectedKeysProtector;
|
||||
import org.junit.AfterClass;
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.util.logging.Logger;
|
|||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint;
|
||||
import org.jivesoftware.smackx.ox.chat.OpenPgpContact;
|
||||
import org.jivesoftware.smackx.ox.chat.OpenPgpFingerprints;
|
||||
|
@ -50,6 +49,7 @@ import org.jivesoftware.smackx.ox.exception.SmackOpenPgpException;
|
|||
import org.jivesoftware.smackx.ox.util.KeyBytesAndFingerprint;
|
||||
|
||||
import de.vanitasvitae.crypto.pgpainless.key.UnprotectedKeysProtector;
|
||||
import org.bouncycastle.util.encoders.Base64;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -57,6 +57,7 @@ import org.jxmpp.jid.BareJid;
|
|||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
||||
public class DryOxEncryptionTest extends OxTestSuite {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(DryOxEncryptionTest.class.getName());
|
||||
|
@ -92,6 +93,9 @@ public class DryOxEncryptionTest extends OxTestSuite {
|
|||
aliceProvider.importSecretKey(alice, aliceKey.getBytes());
|
||||
bobProvider.importSecretKey(bob, bobKey.getBytes());
|
||||
|
||||
aliceStore.setPrimaryOpenPgpKeyPairFingerprint(aliceKey.getFingerprint());
|
||||
bobStore.setPrimaryOpenPgpKeyPairFingerprint(bobKey.getFingerprint());
|
||||
|
||||
byte[] alicePubBytes = aliceStore.getPublicKeyRingBytes(alice, aliceKey.getFingerprint());
|
||||
byte[] bobPubBytes = bobStore.getPublicKeyRingBytes(bob, bobKey.getFingerprint());
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ import org.jivesoftware.smackx.ox.listener.internal.SignElementReceivedListener;
|
|||
import org.jivesoftware.smackx.ox.listener.internal.SigncryptElementReceivedListener;
|
||||
import org.jivesoftware.smackx.ox.util.KeyBytesAndFingerprint;
|
||||
import org.jivesoftware.smackx.ox.util.PubSubDelegate;
|
||||
import org.jivesoftware.smackx.ox.util.SecretKeyBackupHelper;
|
||||
import org.jivesoftware.smackx.pep.PEPListener;
|
||||
import org.jivesoftware.smackx.pep.PEPManager;
|
||||
import org.jivesoftware.smackx.pubsub.EventElement;
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
|
@ -47,9 +48,12 @@ public class OpenPgpFingerprints {
|
|||
Set<OpenPgpV4Fingerprint> availableKeys,
|
||||
Map<OpenPgpV4Fingerprint, Throwable> unfetchableKeys) {
|
||||
this.jid = jid;
|
||||
this.announcedKeys = Collections.unmodifiableSet(announcedKeys);
|
||||
this.availableKeys = Collections.unmodifiableSet(availableKeys);
|
||||
this.unfetchableKeys = Collections.unmodifiableMap(unfetchableKeys);
|
||||
this.announcedKeys = Collections.unmodifiableSet(Objects.requireNonNull(announcedKeys,
|
||||
"Set of announced keys MUST NOT be null."));
|
||||
this.availableKeys = Collections.unmodifiableSet(Objects.requireNonNull(availableKeys,
|
||||
"Set of available keys MUST NOT be null."));
|
||||
this.unfetchableKeys = Collections.unmodifiableMap(Objects.requireNonNull(unfetchableKeys,
|
||||
"Map of unfetchable keys MUST NOT be null."));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
package org.jivesoftware.smackx.ox;
|
||||
/**
|
||||
*
|
||||
* Copyright 2018 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.ox.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -8,6 +24,8 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.jivesoftware.smackx.ox.OpenPgpProvider;
|
||||
import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint;
|
||||
import org.jivesoftware.smackx.ox.element.SecretkeyElement;
|
||||
import org.jivesoftware.smackx.ox.exception.InvalidBackupCodeException;
|
||||
import org.jivesoftware.smackx.ox.exception.MissingOpenPgpKeyPairException;
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.ox;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.ox.chat.OpenPgpFingerprints;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
|
||||
public class OpenPgpFingerprintsTest extends SmackTestSuite {
|
||||
|
||||
private static final OpenPgpV4Fingerprint fingerprint1 = new OpenPgpV4Fingerprint("47696d6d6520323020636861726163746572730a");
|
||||
private static final OpenPgpV4Fingerprint fingerprint2 = new OpenPgpV4Fingerprint("492e206e6565642e20656173746572656767730a");
|
||||
private static final OpenPgpV4Fingerprint fingerprint3 = new OpenPgpV4Fingerprint("4d6f7265206f66207468656d21204d6f7265210a");
|
||||
|
||||
@Test
|
||||
public void activeKeysTest() {
|
||||
Set<OpenPgpV4Fingerprint> announced = new HashSet<>();
|
||||
announced.add(fingerprint1);
|
||||
announced.add(fingerprint2);
|
||||
|
||||
Set<OpenPgpV4Fingerprint> available = new HashSet<>();
|
||||
available.add(fingerprint2);
|
||||
available.add(fingerprint3);
|
||||
|
||||
OpenPgpFingerprints fingerprints = new OpenPgpFingerprints(
|
||||
JidTestUtil.BARE_JID_1,
|
||||
announced,
|
||||
available,
|
||||
new HashMap<OpenPgpV4Fingerprint, Throwable>());
|
||||
|
||||
assertEquals(announced, fingerprints.getAnnouncedKeys());
|
||||
assertEquals(available, fingerprints.getAvailableKeys());
|
||||
assertEquals(JidTestUtil.BARE_JID_1, fingerprints.getJid());
|
||||
assertEquals(0, fingerprints.getUnfetchableKeys().size());
|
||||
|
||||
Set<OpenPgpV4Fingerprint> active = new HashSet<>();
|
||||
active.add(fingerprint2);
|
||||
|
||||
assertEquals(active, fingerprints.getActiveKeys());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue