From 5828f390c1f689162eead39fbddb02afabe70f4a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 8 Jan 2025 16:45:41 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20tests=20for=20missing=20trust?= =?utf8?q?=20and/or=20score=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fcp/plugin/WebOfTrustPluginTest.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java index cec4542..da95d87 100644 --- a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java +++ b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java @@ -284,6 +284,52 @@ public class WebOfTrustPluginTest { } @Test + public void getIdentityTrustCanHandleMissingTrustValue() throws Exception { + TestFcpConnection fcpConnection = createConnectionThatDeliversIdentityWithoutTrustButAScore(); + WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); + OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap()); + CalculatedTrust calculatedTrust = webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id"); + assertThat(calculatedTrust.getTrust(), nullValue()); + assertThat(calculatedTrust.getScore(), equalTo(56)); + assertThat(calculatedTrust.getRank(), equalTo(1)); + } + + private TestFcpConnection createConnectionThatDeliversIdentityWithoutTrustButAScore() { + return createFcpConnection(message -> (listener, connection) -> { + Map fields = createWebOfTrustReplyFields("Identity", true, + entries("Identities.Amount", "1"), identityNick0, + entries("Trusts.0.Value", "Nonexistent"), + entries("Scores.Amount", "1"), scoreValue + ); + FcpMessage replyMessage = createPluginReply(message, fields); + listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null)); + }); + } + + @Test + public void getIdentityTrustCanHandleMissingScoreAndRank() throws Exception { + TestFcpConnection fcpConnection = createConnectionThatDeliversIdentityWithTrustButWithoutScore(); + WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); + OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap()); + CalculatedTrust calculatedTrust = webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id"); + assertThat(calculatedTrust.getTrust(), equalTo((byte) 56)); + assertThat(calculatedTrust.getScore(), nullValue()); + assertThat(calculatedTrust.getRank(), nullValue()); + } + + private TestFcpConnection createConnectionThatDeliversIdentityWithTrustButWithoutScore() { + return createFcpConnection(message -> (listener, connection) -> { + Map fields = createWebOfTrustReplyFields("Identity", true, + entries("Identities.Amount", "1"), identityNick0, + entries("Trusts.Amount", "1"), trustValue, + entries("Scores.0.Value", "Nonexistent") + ); + FcpMessage replyMessage = createPluginReply(message, fields); + listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null)); + }); + } + + @Test public void getIdentityTrustFailsWhenDifferentReplyIsSentByPlugin() { FcpConnection fcpConnection = createConnectionThatSendsOtherMessage(); WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); -- 2.7.4