Skip to content

Commit 3754339

Browse files
authored
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
2 parents c76e817 + a97a93b commit 3754339

File tree

10 files changed

+111
-10
lines changed

10 files changed

+111
-10
lines changed

.github/codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
coverage:
2-
range: 5..80
2+
range: 15..80
33
round: down
44
precision: 2

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To run the application in debug mode, replace `mvn` with `mvnDebug` in the comma
3939

4040
```
4141
mvn test
42-
open target/site/jacoco/index.html
42+
open target/site/jacoco/index.html
4343
```
4444

4545

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>ai.elimu</groupId>
55
<artifactId>webapp</artifactId>
66
<packaging>war</packaging>
7-
<version>2.2.127-SNAPSHOT</version>
7+
<version>2.2.128-SNAPSHOT</version>
88

99
<properties>
1010
<java.version>11</java.version>

src/main/java/ai/elimu/model/contributor/Contributor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class Contributor extends BaseEntity {
3333

3434
// TODO: add registrationPlatform
3535

36+
// TODO: add registrationProvider
37+
3638
// @Column(unique=true)
3739
private String providerIdGoogle;
3840

@@ -45,9 +47,9 @@ public class Contributor extends BaseEntity {
4547
// @Column(unique=true)
4648
private String providerIdGitHub;
4749

50+
// @Column(unique=true)
4851
private String providerIdDiscord;
4952

50-
// @Column(unique=true)
5153
private String usernameGitHub;
5254

5355
private String usernameDiscord;

src/main/java/ai/elimu/rest/v2/crowdsource/ContributorsRestControllerWeb3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public String handleGetRequest(
6969
logger.info("jsonResponse: " + jsonResponse);
7070
return jsonResponse;
7171
}
72-
72+
providerIdWeb3 = providerIdWeb3.toLowerCase();
7373
String providerIdWeb3Signature = contributorJSONObject.getString("providerIdWeb3Signature");
7474
logger.info("providerIdWeb3Signature: " + providerIdWeb3Signature);
7575
if (StringUtils.isBlank(providerIdWeb3Signature)) {

src/main/java/ai/elimu/util/db/DbMigrationHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ public synchronized void performDatabaseMigration(WebApplicationContext webAppli
8383
logger.error(ex);
8484
}
8585

86+
// Update current version
87+
logger.info("Updating current version (" + scriptVersion + ")");
8688
DbMigration dbMigration = new DbMigration();
8789
dbMigration.setVersion(scriptVersion);
8890
dbMigration.setScript(script);
8991
dbMigration.setCalendar(Calendar.getInstance());
9092
dbMigrationDao.create(dbMigration);
93+
94+
logger.info("Database migration complete!");
9195
}
9296
}
9397
}

src/main/java/ai/elimu/web/SignOnControllerWeb3.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class SignOnControllerWeb3 {
3333
@Autowired
3434
private ContributorDao contributorDao;
3535

36-
@RequestMapping("/sign-on/web3")
36+
@RequestMapping(value="/sign-on/web3", method=RequestMethod.GET)
3737
public String handleGetRequest(HttpServletRequest request) throws IOException {
3838
logger.info("handleGetRequest");
3939

@@ -52,12 +52,12 @@ public String handleAuthorization(
5252
@RequestParam String signature
5353
) throws IOException {
5454
logger.info("handleAuthorization");
55-
5655
logger.info("address: " + address);
5756
if (StringUtils.isBlank(address)) {
5857
return "redirect:/sign-on/web3?error=Missing address";
5958
}
60-
59+
address = address.toLowerCase();
60+
6161
logger.info("signature: " + signature);
6262
if (StringUtils.isBlank(signature)) {
6363
return "redirect:/sign-on/web3?error=Missing signature";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 2.2.127
2+
3+
# Convert existing Ethereum addresses to lower-case
4+
UPDATE Contributor SET providerIdWeb3 = LOWER(providerIdWeb3);

src/main/webapp/static/js/web3provider.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async function disconnect() {
8585
console.log("Killing the wallet connection", provider);
8686

8787
// TODO: Which providers have close method?
88-
if (provider.close) {
88+
if (provider && provider.close) {
8989
await provider.close();
9090

9191
// If the cached provider is not cleared,
@@ -94,7 +94,9 @@ async function disconnect() {
9494
// Depending on your use case you may want or want not his behavir.
9595
provider = null;
9696
}
97-
await web3Modal.clearCachedProvider();
97+
if (web3Modal) {
98+
await web3Modal.clearCachedProvider();
99+
}
98100
}
99101

100102
/**
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package ai.elimu.web;
2+
3+
import static org.junit.Assert.*;
4+
import org.junit.Before;
5+
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.MediaType;
11+
import org.springframework.test.context.ContextConfiguration;
12+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13+
import org.springframework.test.web.servlet.MockMvc;
14+
import org.springframework.test.web.servlet.MvcResult;
15+
import org.springframework.test.web.servlet.RequestBuilder;
16+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
17+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
18+
19+
@RunWith(SpringJUnit4ClassRunner.class)
20+
@ContextConfiguration(locations={
21+
"file:src/main/webapp/WEB-INF/spring/applicationContext.xml",
22+
"file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml"
23+
})
24+
public class SignOnControllerWeb3Test {
25+
26+
@Autowired
27+
private SignOnControllerWeb3 signOnControllerWeb3;
28+
29+
private MockMvc mockMvc;
30+
31+
@Before
32+
public void setup() {
33+
assertNotNull(signOnControllerWeb3);
34+
mockMvc = MockMvcBuilders.standaloneSetup(signOnControllerWeb3).build();
35+
assertNotNull(mockMvc);
36+
}
37+
38+
@Test
39+
public void testHandleGetRequest() throws Exception {
40+
RequestBuilder requestBuilder = MockMvcRequestBuilders
41+
.get("/sign-on/web3");
42+
MvcResult mvcResult = mockMvc.perform(requestBuilder).andReturn();
43+
assertEquals(HttpStatus.OK.value(), mvcResult.getResponse().getStatus());
44+
assertEquals("sign-on-web3", mvcResult.getModelAndView().getViewName());
45+
}
46+
47+
@Test
48+
public void testHandleAuthorization_missingParameters() throws Exception {
49+
RequestBuilder requestBuilder = MockMvcRequestBuilders
50+
.post("/sign-on/web3")
51+
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
52+
MvcResult mvcResult = mockMvc.perform(requestBuilder).andReturn();
53+
assertEquals(HttpStatus.BAD_REQUEST.value(), mvcResult.getResponse().getStatus());
54+
assertNull(mvcResult.getModelAndView());
55+
}
56+
57+
@Test
58+
public void testHandleAuthorization_emptyParameters() throws Exception {
59+
RequestBuilder requestBuilder = MockMvcRequestBuilders
60+
.post("/sign-on/web3")
61+
.param("address", "")
62+
.param("signature", "0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400")
63+
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
64+
MvcResult mvcResult = mockMvc.perform(requestBuilder).andReturn();
65+
assertEquals(HttpStatus.MOVED_TEMPORARILY.value(), mvcResult.getResponse().getStatus());
66+
assertEquals("redirect:/sign-on/web3?error=Missing address", mvcResult.getModelAndView().getViewName());
67+
68+
requestBuilder = MockMvcRequestBuilders
69+
.post("/sign-on/web3")
70+
.param("address", "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe")
71+
.param("signature", "")
72+
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
73+
mvcResult = mockMvc.perform(requestBuilder).andReturn();
74+
assertEquals(HttpStatus.MOVED_TEMPORARILY.value(), mvcResult.getResponse().getStatus());
75+
assertEquals("redirect:/sign-on/web3?error=Missing signature", mvcResult.getModelAndView().getViewName());
76+
}
77+
78+
@Test
79+
public void testHandleAuthorization_invalidSignature() throws Exception {
80+
RequestBuilder requestBuilder = MockMvcRequestBuilders
81+
.post("/sign-on/web3")
82+
.param("address", "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe")
83+
.param("signature", "0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400")
84+
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
85+
MvcResult mvcResult = mockMvc.perform(requestBuilder).andReturn();
86+
assertEquals(HttpStatus.MOVED_TEMPORARILY.value(), mvcResult.getResponse().getStatus());
87+
assertEquals("redirect:/sign-on/web3?error=Invalid signature", mvcResult.getModelAndView().getViewName());
88+
}
89+
}

0 commit comments

Comments
 (0)