1 | package fr.sii.ogham.testing.sms.simulator.jsmpp; | |
2 | ||
3 | import java.security.SecureRandom; | |
4 | import java.util.Random; | |
5 | ||
6 | import org.jsmpp.PDUStringException; | |
7 | import org.jsmpp.util.MessageIDGenerator; | |
8 | import org.jsmpp.util.MessageId; | |
9 | import org.jsmpp.util.RandomMessageIDGenerator; | |
10 | ||
11 | /** | |
12 | * This implementation doesn't use {@link SecureRandom} (unlike | |
13 | * {@link RandomMessageIDGenerator}). {@link SecureRandom} can potentially block | |
14 | * the simulator process because on some operating systems /dev/random waits for | |
15 | * a certain amount of "noise" to be generated on the host machine before | |
16 | * returning a result. | |
17 | * | |
18 | * <p> | |
19 | * jSMPP is used in tests so timeouts have small values that's why we can't wait | |
20 | * until enough "noise" is generated. | |
21 | * | |
22 | * @author Aurélien Baudet | |
23 | * @see RandomMessageIDGenerator | |
24 | * @see SecureRandom | |
25 | * @see "https://docs.oracle.com/cd/E13209_01/wlcp/wlss30/configwlss/jvmrand.html" | |
26 | */ | |
27 | public class UnsecureRandomMessageIDGenerator implements MessageIDGenerator { | |
28 | private final Random random; | |
29 | ||
30 | @SuppressWarnings("java:S2245") | |
31 | public UnsecureRandomMessageIDGenerator() { | |
32 | random = new Random(); | |
33 | } | |
34 | ||
35 | @SuppressWarnings({ "squid:S00112", "squid:S109" }) // code copied from Cloudhopper | |
36 | @Override | |
37 | public MessageId newMessageId() { | |
38 | /* | |
39 | * use database sequence convert into hex representation or if not using | |
40 | * database using random | |
41 | */ | |
42 | try { | |
43 | synchronized (random) { | |
44 |
5
1. newMessageId : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/UnsecureRandomMessageIDGenerator::newMessageId → SURVIVED 2. newMessageId : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/UnsecureRandomMessageIDGenerator::newMessageId → NO_COVERAGE 3. newMessageId : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/UnsecureRandomMessageIDGenerator::newMessageId → TIMED_OUT 4. newMessageId : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/UnsecureRandomMessageIDGenerator::newMessageId → KILLED 5. newMessageId : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/UnsecureRandomMessageIDGenerator::newMessageId → KILLED |
return new MessageId(Integer.toString(random.nextInt(Integer.MAX_VALUE), 16)); |
45 | } | |
46 | } catch (PDUStringException e) { | |
47 | throw new RuntimeException("Failed creating message id", e); | |
48 | } | |
49 | } | |
50 | } | |
Mutations | ||
44 |
1.1 2.2 3.3 4.4 5.5 |