-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add verification code CLI * Added suggestion from code review * Fixed types * Added extra test * Added CLI dist scripts * Fixed typo * Write code to data instead of config directory
- Loading branch information
1 parent
34581ff
commit db5cf95
Showing
12 changed files
with
346 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
require('../src/cli_verification_code/dev'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { kibanaPackageJson, getDataPath } from '@kbn/utils'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import chalk from 'chalk'; | ||
|
||
import Command from '../cli/command'; | ||
|
||
const program = new Command('bin/kibana-verification-code'); | ||
|
||
program | ||
.version(kibanaPackageJson.version) | ||
.description('Tool to get Kibana verification code') | ||
.action(() => { | ||
const fpath = path.join(getDataPath(), 'verification_code'); | ||
try { | ||
const code = fs.readFileSync(fpath).toString(); | ||
console.log( | ||
`Your verification code is: ${chalk.black.bgCyanBright( | ||
` ${code.substr(0, 3)} ${code.substr(3)} ` | ||
)}` | ||
); | ||
} catch (error) { | ||
console.log(`Couldn't find verification code. | ||
If Kibana hasn't been configured yet, restart Kibana to generate a new code. | ||
Otherwise, you can safely ignore this message and start using Kibana.`); | ||
} | ||
}); | ||
|
||
program.parse(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
require('../setup_node_env'); | ||
require('./cli_verification_code'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
require('../setup_node_env/dist'); | ||
require('./cli_verification_code'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
SCRIPT=$0 | ||
|
||
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. | ||
while [ -h "$SCRIPT" ] ; do | ||
ls=$(ls -ld "$SCRIPT") | ||
# Drop everything prior to -> | ||
link=$(expr "$ls" : '.*-> \(.*\)$') | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=$(dirname "$SCRIPT")/"$link" | ||
fi | ||
done | ||
|
||
DIR="$(dirname "${SCRIPT}")/.." | ||
CONFIG_DIR=${KBN_PATH_CONF:-"$DIR/config"} | ||
NODE="${DIR}/node/bin/node" | ||
test -x "$NODE" | ||
if [ ! -x "$NODE" ]; then | ||
echo "unable to find usable node.js executable." | ||
exit 1 | ||
fi | ||
|
||
if [ -f "${CONFIG_DIR}/node.options" ]; then | ||
KBN_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)" | ||
fi | ||
NODE_OPTIONS="$KBN_NODE_OPTS $NODE_OPTIONS" "${NODE}" "${DIR}/src/cli_verification_code/dist" "$@" |
35 changes: 35 additions & 0 deletions
35
src/dev/build/tasks/bin/scripts/kibana-verification-code.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@echo off | ||
|
||
SETLOCAL ENABLEDELAYEDEXPANSION | ||
|
||
set SCRIPT_DIR=%~dp0 | ||
for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI | ||
|
||
set NODE=%DIR%\node\node.exe | ||
|
||
If Not Exist "%NODE%" ( | ||
Echo unable to find usable node.js executable. | ||
Exit /B 1 | ||
) | ||
|
||
set CONFIG_DIR=%KBN_PATH_CONF% | ||
If ["%KBN_PATH_CONF%"] == [] ( | ||
set "CONFIG_DIR=%DIR%\config" | ||
) | ||
|
||
IF EXIST "%CONFIG_DIR%\node.options" ( | ||
for /F "usebackq eol=# tokens=*" %%i in ("%CONFIG_DIR%\node.options") do ( | ||
If [!NODE_OPTIONS!] == [] ( | ||
set "NODE_OPTIONS=%%i" | ||
) Else ( | ||
set "NODE_OPTIONS=!NODE_OPTIONS! %%i" | ||
) | ||
) | ||
) | ||
|
||
TITLE Kibana Verification Code | ||
"%NODE%" "%DIR%\src\cli_verification_code\dist" %* | ||
|
||
:finally | ||
|
||
ENDLOCAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/plugins/interactive_setup/public/verification_code_form.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { fireEvent, render, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { coreMock } from 'src/core/public/mocks'; | ||
|
||
import { Providers } from './plugin'; | ||
import { VerificationCodeForm } from './verification_code_form'; | ||
|
||
jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({ | ||
htmlIdGenerator: () => () => `id-${Math.random()}`, | ||
})); | ||
|
||
describe('VerificationCodeForm', () => { | ||
jest.setTimeout(20_000); | ||
|
||
it('calls enrollment API when submitting form', async () => { | ||
const coreStart = coreMock.createStart(); | ||
coreStart.http.post.mockResolvedValue({}); | ||
|
||
const onSuccess = jest.fn(); | ||
|
||
const { findByRole, findByLabelText } = render( | ||
<Providers http={coreStart.http}> | ||
<VerificationCodeForm onSuccess={onSuccess} /> | ||
</Providers> | ||
); | ||
fireEvent.input(await findByLabelText('Digit 1'), { | ||
target: { value: '1' }, | ||
}); | ||
fireEvent.input(await findByLabelText('Digit 2'), { | ||
target: { value: '2' }, | ||
}); | ||
fireEvent.input(await findByLabelText('Digit 3'), { | ||
target: { value: '3' }, | ||
}); | ||
fireEvent.input(await findByLabelText('Digit 4'), { | ||
target: { value: '4' }, | ||
}); | ||
fireEvent.input(await findByLabelText('Digit 5'), { | ||
target: { value: '5' }, | ||
}); | ||
fireEvent.input(await findByLabelText('Digit 6'), { | ||
target: { value: '6' }, | ||
}); | ||
fireEvent.click(await findByRole('button', { name: 'Verify', hidden: true })); | ||
|
||
await waitFor(() => { | ||
expect(coreStart.http.post).toHaveBeenLastCalledWith('/internal/interactive_setup/verify', { | ||
body: JSON.stringify({ code: '123456' }), | ||
}); | ||
expect(onSuccess).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('validates form', async () => { | ||
const coreStart = coreMock.createStart(); | ||
const onSuccess = jest.fn(); | ||
|
||
const { findAllByText, findByRole, findByLabelText } = render( | ||
<Providers http={coreStart.http}> | ||
<VerificationCodeForm onSuccess={onSuccess} /> | ||
</Providers> | ||
); | ||
|
||
fireEvent.click(await findByRole('button', { name: 'Verify', hidden: true })); | ||
|
||
await findAllByText(/Enter a verification code/i); | ||
|
||
fireEvent.input(await findByLabelText('Digit 1'), { | ||
target: { value: '1' }, | ||
}); | ||
|
||
await findAllByText(/Enter all six digits/i); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.