Skip to content

Commit

Permalink
Merge pull request #31 from Sakuten/feature/recaptcha
Browse files Browse the repository at this point in the history
Support reCAPTCHA Authenication
  • Loading branch information
anharu2394 authored Jul 27, 2018
2 parents de05384 + 79794c5 commit d671d26
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ API_PORT=8888
API_HOST=localhost

DB_PASSWORD=password

# Replace them with your keys.
# Currently, these keys are test keys for automated testing.
# Details: https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha-v2-what-should-i-do
RECAPTCHA_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
RECAPTCHA_SECRET_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"SECRET_KEY": {
"description": "The encryption key to use in authenication (DON'T USE THIS IN PRODUCTION)",
"value": "my4ViaJb4rek9YIRLFS_3E0fT88QiRhdK8uKOjHXhrA="
},
"RECAPTCHA_SECRET_KEY": {
"description": "The secret key to use in reCAPTCHA validation (DON'T USE THIS IN PRODUCTION)",
"value": "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"
}
},
"formation": {},
Expand Down
2 changes: 1 addition & 1 deletion backend
Submodule backend updated 44 files
+10 −0 .editorconfig
+0 −59 .github/ISSUE_TEMPLATE.md
+43 −0 .github/ISSUE_TEMPLATE/bug_report.md
+32 −0 .github/ISSUE_TEMPLATE/feature_request.md
+14 −7 .github/PULL_REQUEST_TEMPLATE.md
+7 −0 .gitignore
+4 −0 Pipfile
+93 −24 Pipfile.lock
+38 −5 api/app.py
+19 −1 api/auth.py
+6 −0 api/config.py
+45 −7 api/models.py
+128 −30 api/routes/api.py
+16 −5 api/routes/auth.py
+17 −5 api/schemas.py
+12 −0 api/spec/definitions/Certificate.yml
+10 −0 api/spec/definitions/ErrorMessage.yml
+6 −0 api/spec/definitions/Token.yml
+42 −0 api/spec/routes/api/applications.yml
+41 −0 api/spec/routes/api/applications/cancel.yml
+37 −0 api/spec/routes/api/applications/idx.yml
+28 −0 api/spec/routes/api/classrooms.yml
+25 −0 api/spec/routes/api/classrooms/idx.yml
+28 −0 api/spec/routes/api/lotteries.yml
+59 −0 api/spec/routes/api/lotteries/apply.yml
+53 −0 api/spec/routes/api/lotteries/cancel.yml
+51 −0 api/spec/routes/api/lotteries/draw.yml
+25 −0 api/spec/routes/api/lotteries/idx.yml
+39 −0 api/spec/routes/api/status.yml
+33 −0 api/spec/routes/auth.yml
+276 −0 api/spec/template.yml
+13 −0 api/swagger.py
+4 −0 app.json
+19 −0 cards-print/Makefile
+9 −0 cards-print/cards.py
+49 −0 cards-print/mkhtml.py
+22 −0 cards-print/mkqr.py
+69 −0 cards-print/template/cards.html.j2
+40 −0 docs/uml/api-models_class.uml
+6 −0 docs/uml/app_flow.uml
+206 −130 test/test_lottery.py
+10 −0 test/test_misc.py
+26 −34 test/test_user.py
+33 −15 test/utils.py
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
- backend
environment:
- "REACT_APP_API_SERVER=http://${API_HOST}:${API_PORT}"
- "REACT_APP_RECAPTCHA_KEY=${RECAPTCHA_KEY}"
- "PORT=${PORT}"
- "HOST=0.0.0.0"
- "SHELL=/bin/sh"
Expand All @@ -43,6 +44,7 @@ services:
- FLASK_APP=app.py
- FLASK_CONFIGURATION=development
- FLASK_ENV=development
- RECAPTCHA_SECRET_KEY=${RECAPTCHA_SECRET_KEY}
command: "/bin/bash -c 'pipenv run start:dep & pipenv run start:flask --port ${API_PORT} --host 0.0.0.0'"
working_dir: "/code"
volumes:
Expand Down
2 changes: 1 addition & 1 deletion frontend
Submodule frontend updated 50 files
+5 −0 package.json
+1 −0 public/index.html
+12 −1 src/api/operation/__mocks__/applyLottery.js
+3 −1 src/api/operation/__mocks__/cancelLottery.js
+18 −0 src/api/operation/__mocks__/getApplications.js
+50 −52 src/api/operation/__mocks__/getClassrooms.js
+226 −228 src/api/operation/__mocks__/getLotteries.js
+15 −17 src/api/operation/__mocks__/getStatus.js
+1 −0 src/api/operation/__mocks__/index.js
+2 −2 src/api/operation/applyLottery.js
+3 −3 src/api/operation/authenicate.js
+1 −1 src/api/operation/cancelLottery.js
+9 −0 src/api/operation/getApplications.js
+1 −1 src/api/operation/getClassrooms.js
+1 −1 src/api/operation/getLotteries.js
+1 −1 src/api/operation/getStatus.js
+1 −0 src/api/operation/index.js
+4 −2 src/api/request.js
+3 −3 src/component/ApplicationList.js
+1 −1 src/component/ClassroomSelect.js
+2 −2 src/component/ErrorList.js
+13 −0 src/component/Home.js
+1 −1 src/component/LotterySelect.js
+22 −10 src/component/__tests__/ApplicationList.spec.js
+29 −0 src/component/__tests__/Home.spec.js
+36 −24 src/component/__tests__/__snapshots__/ApplicationList.spec.js.snap
+4 −4 src/component/__tests__/__snapshots__/ClassroomSelect.spec.js.snap
+4 −4 src/component/__tests__/__snapshots__/ErrorList.spec.js.snap
+121 −0 src/component/__tests__/__snapshots__/Home.spec.js.snap
+4 −4 src/component/__tests__/__snapshots__/LotterySelect.spec.js.snap
+13 −6 src/container/App.js
+1 −1 src/container/ApplicationView.js
+7 −2 src/container/LoginView.js
+24 −6 src/container/__tests__/App.spec.js
+3 −3 src/container/__tests__/ApplicationView.spec.js
+0 −6 src/container/__tests__/LoginView.spec.js
+361 −23 src/container/__tests__/__snapshots__/App.spec.js.snap
+34 −7 src/container/__tests__/__snapshots__/ApplicationView.spec.js.snap
+198 −7 src/container/__tests__/__snapshots__/LoginView.spec.js.snap
+2 −2 src/event/__tests__/application.spec.js
+0 −10 src/event/__tests__/credential.spec.js
+2 −2 src/event/application.js
+5 −6 src/event/credential.js
+10 −2 src/index.js
+10 −0 src/store/__tests__/application.spec.js
+3 −13 src/store/__tests__/credential.spec.js
+14 −3 src/store/application.js
+4 −14 src/store/credential.js
+11 −0 src/store/index.js
+294 −526 yarn.lock
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[build.environment]
NODE_ENV = "development"
BABEL_ENV = "development"
REACT_APP_API_SERVER = "https://sakuten-api-preflight.herokuapp.com"
REACT_APP_API_SERVER = "https://sakuten-api-testflight.herokuapp.com"

[context.production]
command = "yarn build --production"
Expand Down
4 changes: 3 additions & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
- backend
environment:
- "REACT_APP_API_SERVER=http://backend:${API_PORT}"
- "REACT_APP_RECAPTCHA_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
- "PORT=${PORT}"
- "HOST=0.0.0.0"
working_dir: "/code"
Expand All @@ -46,8 +47,9 @@ services:
- db
environment:
- FLASK_APP=app.py
- FLASK_CONFIGURATION=testing
- FLASK_ENV=development
- FLASK_DEBUG=1
- RECAPTCHA_SECRET_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
command: "start:flask --port ${API_PORT} --host 0.0.0.0"
working_dir: "/code"
volumes:
Expand Down
35 changes: 28 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,34 @@ describe('Login', function () {
browser.reload()
})

it('Can successfully authenicate with example1', function () {
it('Can successfully renders top page', function () {
browser.url('http://frontend:8000/')
browser.waitForVisible('p', 3000)
const title = $('p').getText()
expect(title).to.include('Home')
})

it('Routes to login page', function () {
browser.url('http://frontend:8000/')
$('input[name="username"]').setValue('example1')
$('input[name="password"]').setValue('example1')
$('button').click()
browser.waitForVisible('h1', 3000)
const title = $('h1').getText()
expect(title).to.equal('Logged in as example1')
browser.waitForVisible('[data-test="home-login"]', 3000)
$('[data-test="home-login"]').click()
expect(browser.getUrl()).to.equal('http://frontend:8000/lottery/login')
})

it('Can successfully authenicate with example1', function () {
browser.url('http://frontend:8000/lottery/login')
browser.waitForVisible('iframe', 3000)
$('[data-test="loginview-username"]').setValue('example1')
browser.frame($('iframe').value)
$('.recaptcha-checkbox').click()
browser.waitForVisible('.recaptcha-checkbox-checkmark', 5000)
browser.frameParent()
$('[data-test="loginview-login"]').click()
setTimeout(() => {
browser.refresh()
browser.waitForVisible('h1', 3000)
const title = $('h1').getText()
expect(title).to.equal('Logged in as example1')
}, 1000)
})
})
3 changes: 3 additions & 0 deletions unit_test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
command: "test"
environment:
- "CI=1"
- "REACT_APP_RECAPTCHA_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
volumes:
- "../${FRONTEND_DIR}:/code"
- /code/node_modules
Expand All @@ -15,5 +16,7 @@ services:
dockerfile: ../unit_test/Dockerfile.backend
context: ../${BACKEND_DIR}
command: "test"
environment:
- RECAPTCHA_SECRET_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
volumes:
- "../${BACKEND_DIR}:/code"

0 comments on commit d671d26

Please sign in to comment.