Skip to content

Commit 8ccc43a

Browse files
Fix Java runtime version and test endpoints
Co-authored-by: hrj <345879+hrj@users.noreply.github.com>
1 parent 7030ad5 commit 8ccc43a

7 files changed

Lines changed: 26 additions & 24 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v2
15-
- name: Set up JDK 1.11
15+
- name: Set up JDK 17
1616
uses: actions/setup-java@v1
1717
with:
18-
java-version: 1.11
18+
java-version: 17
1919
- uses: sbt/setup-sbt@v1
2020
- name: Run tests
2121
run: sbt test assembly

.github/workflows/docker-latest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up JDK
1818
uses: actions/setup-java@v1
1919
with:
20-
java-version: 1.16
20+
java-version: 17
2121

2222
- uses: sbt/setup-sbt@v1
2323

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: scala
2-
jdk: openjdk11
2+
jdk: openjdk17
33
scala:
44
- 2.13.2
55
script:

src/main/scala/lc/server/Server.scala

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ class Server(
3131
.POST(
3232
"/v2/captcha",
3333
(request) => {
34-
val paramEither = Parameters.codec.decode(ByteBuffer.wrap(request.getBodyString().getBytes("UTF-8")))
35-
val id = paramEither match {
36-
case Right(param) => captchaManager.getChallenge(param)
37-
case Left(err) => Left(Error("Invalid parameters: " + err.toString))
34+
val bodyStr = request.getBodyString().trim.replaceAll("\u0000", "")
35+
val paramEither = Parameters.codec.decode(ByteBuffer.wrap(bodyStr.getBytes("UTF-8")))
36+
paramEither match {
37+
case Right(param) =>
38+
val id = captchaManager.getChallenge(param)
39+
getResponse(id, headerMap)
40+
case Left(err) =>
41+
getResponse(Left(Error("Invalid parameters: " + err.toString)), headerMap)
3842
}
39-
getResponse(id, headerMap)
4043
}
4144
)
4245
.GET(
@@ -56,12 +59,15 @@ class Server(
5659
.POST(
5760
"/v2/answer",
5861
(request) => {
59-
val answerEither = Answer.codec.decode(ByteBuffer.wrap(request.getBodyString().getBytes("UTF-8")))
60-
val result = answerEither match {
61-
case Right(answer) => captchaManager.checkAnswer(answer)
62-
case Left(err) => Left(Error("Invalid answer format: " + err.toString))
62+
val bodyStr = request.getBodyString().trim.replaceAll("\u0000", "")
63+
val answerEither = Answer.codec.decode(ByteBuffer.wrap(bodyStr.getBytes("UTF-8")))
64+
answerEither match {
65+
case Right(answer) =>
66+
val result = captchaManager.checkAnswer(answer)
67+
getResponse(result, headerMap)
68+
case Left(err) =>
69+
getResponse(Left(Error("Invalid answer format: " + err.toString)), headerMap)
6370
}
64-
getResponse(result, headerMap)
6571
}
6672
)
6773
if (playgroundEnabled) {

test-zio.scala

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/locustfile-functional.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class QuickStartUser(SequentialTaskSet):
2424
def captcha(self):
2525
captcha_params = {"level":"debug","media":"image/png","input_type":"text", "size":"350x100"}
2626

27-
with self.client.post(path="/v2/captcha", json=captcha_params, name="/captcha", catch_response = True) as resp:
27+
with self.client.post(url="/v2/captcha", json=captcha_params, name="/captcha", catch_response = True) as resp:
2828
if resp.status_code != 200:
2929
resp.failure("Status was not 200: " + resp.text)
3030
captchaJson = resp.json()
3131
uuid = captchaJson.get("id")
3232
if not uuid:
3333
resp.failure("uuid not returned on /captcha endpoint: " + resp.text)
3434

35-
with self.client.get(path="/v2/media?id=%s" % uuid, name="/media", stream=True, catch_response = True) as resp:
35+
with self.client.get(url="/v2/media?id=%s" % uuid, name="/media", stream=True, catch_response = True) as resp:
3636
if resp.status_code != 200:
3737
resp.failure("Status was not 200: " + resp.text)
3838

@@ -41,7 +41,7 @@ def captcha(self):
4141
ocrAnswer = self.solve(uuid, media)
4242

4343
answerBody = {"answer": ocrAnswer,"id": uuid}
44-
with self.client.post(path='/v2/answer', json=answerBody, name="/answer", catch_response=True) as resp:
44+
with self.client.post(url='/v2/answer', json=answerBody, name="/answer", catch_response=True) as resp:
4545
if resp.status_code != 200:
4646
resp.failure("Status was not 200: " + resp.text)
4747
else:

tests/locustfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def captcha(self):
2626
# TODO: Iterate over parameters for a more comprehensive test
2727
captcha_params = {"level":"easy","media":"image/png","input_type":"text", "size":"350x100"}
2828

29-
resp = self.client.post(path="/v2/captcha", json=captcha_params, name="/captcha")
29+
resp = self.client.post(url="/v2/captcha", json=captcha_params, name="/captcha")
3030
if resp.status_code != 200:
3131
print("\nError on /captcha endpoint: ")
3232
print(resp)
@@ -36,14 +36,14 @@ def captcha(self):
3636
uuid = json.loads(resp.text).get("id")
3737
answerBody = {"answer": "qwer123","id": uuid}
3838

39-
resp = self.client.get(path="/v2/media?id=%s" % uuid, name="/media")
39+
resp = self.client.get(url="/v2/media?id=%s" % uuid, name="/media")
4040
if resp.status_code != 200:
4141
print("\nError on /media endpoint: ")
4242
print(resp)
4343
print(resp.text)
4444
print("----------------END.MEDIA-------------------\n\n")
4545

46-
resp = self.client.post(path='/v2/answer', json=answerBody, name="/answer")
46+
resp = self.client.post(url='/v2/answer', json=answerBody, name="/answer")
4747
if resp.status_code != 200:
4848
print("\nError on /answer endpoint: ")
4949
print(resp)

0 commit comments

Comments
 (0)