Skip to content

Commit c5ae2b5

Browse files
authored
Merge pull request #520 from ZIMkaRU/feature/add-endpoints-for-recaptcha-to-overcome-cors
Add endpoints for recaptcha to overcome cors on framework
2 parents bdfe10f + 2c79254 commit c5ae2b5

5 files changed

Lines changed: 79 additions & 1 deletion

File tree

test/helpers/helpers.mock-rest-v2.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ const getMockDataOpts = () => ({
5050
delete_token: null,
5151
login: null,
5252
login_verify: null,
53+
captcha_providers: null,
54+
captcha_required: null,
5355
platform_status: null
5456
})
5557

5658
const getExtraMockMethods = () => (new Map([
5759
['post', {
5860
'/v2/login': 'login',
59-
'/v2/login/verify': 'login_verify'
61+
'/v2/login/verify': 'login_verify',
62+
'/v2/int/captcha/providers': 'captcha_providers',
63+
'/v2/int/captcha/required': 'captcha_required'
6064
}]
6165
]))
6266

test/helpers/mock-data.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ module.exports = new Map([
2525
'2023-03-21T12:00:00.000Z'
2626
]
2727
],
28+
[
29+
'captcha_providers',
30+
['hcaptcha']
31+
],
32+
[
33+
'captcha_required',
34+
true
35+
],
2836
[
2937
'generate_token',
3038
['pub:api:88888888-4444-4444-4444-121212121212-caps:s:o:f:w:wd:a-write']

test/test-cases/api-sync-mode-sqlite-test-cases.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,48 @@ module.exports = (
175175
assert.isString(res.body.result[1])
176176
})
177177

178+
it('it should be successfully performed by the getCaptchaProviders method', async function () {
179+
this.timeout(5000)
180+
181+
const res = await agent
182+
.post(`${basePath}/json-rpc`)
183+
.type('json')
184+
.send({
185+
method: 'getCaptchaProviders',
186+
id: 5
187+
})
188+
.expect('Content-Type', /json/)
189+
.expect(200)
190+
191+
assert.isObject(res.body)
192+
assert.propertyVal(res.body, 'id', 5)
193+
assert.isArray(res.body.result)
194+
assert.isString(res.body.result[0])
195+
assert.strictEqual(res.body.result[0], 'hcaptcha')
196+
})
197+
198+
it('it should be successfully performed by the isCaptchaRequired method', async function () {
199+
this.timeout(5000)
200+
201+
const res = await agent
202+
.post(`${basePath}/json-rpc`)
203+
.type('json')
204+
.send({
205+
method: 'isCaptchaRequired',
206+
params: {
207+
method: 'login'
208+
},
209+
id: 5
210+
})
211+
.expect('Content-Type', /json/)
212+
.expect(200)
213+
214+
assert.isObject(res.body)
215+
assert.propertyVal(res.body, 'id', 5)
216+
assert.isBoolean(res.body.result)
217+
assert.isOk(res.body.result)
218+
})
219+
178220
it('it should be successfully performed by the signIn method', async function () {
179221
this.timeout(5000)
180222

workers/loc.api/http.request/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ class ExpandedRESTv2 extends RESTv2 {
5656
return makeRequestToBFX(() => this
5757
._makePublicPostRequest('/login/verify', body))
5858
}
59+
60+
async getCaptchaProviders (body) {
61+
return makeRequestToBFX(() => this
62+
._makePublicPostRequest('/int/captcha/providers', body))
63+
}
64+
65+
async isCaptchaRequired (body) {
66+
return makeRequestToBFX(() => this
67+
._makePublicPostRequest('/int/captcha/required', body))
68+
}
5969
}
6070

6171
decorateInjectable(HTTPRequest, depsTypes)

workers/loc.api/service.report.framework.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ class FrameworkReportService extends ReportService {
9999
}, 'verifyOnBFX', args, cb)
100100
}
101101

102+
getCaptchaProviders (space, args, cb) {
103+
return this._responder(() => {
104+
return this._httpRequest.getRequest()
105+
.getCaptchaProviders(args?.params)
106+
}, 'getCaptchaProviders', args, cb)
107+
}
108+
109+
isCaptchaRequired (space, args, cb) {
110+
return this._responder(() => {
111+
return this._httpRequest.getRequest()
112+
.isCaptchaRequired(args?.params)
113+
}, 'isCaptchaRequired', args, cb)
114+
}
115+
102116
isStagingBfxApi (space, args, cb) {
103117
return this._responder(() => {
104118
return this._authenticator.isStagingBfxApi()

0 commit comments

Comments
 (0)