Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ask for password if -p is not provided #4153

Merged
merged 2 commits into from
Jan 13, 2020

Conversation

spena
Copy link
Member

@spena spena commented Dec 16, 2019

Description

What behavior do you want to change, why, how does your patch achieve the changes?

If the -p or --password parameters are not provided when using authentication, then the CLI will ask the user to enter the password on the prompt:

$  ./bin/ksql --user user1 http://localhost:8088
Enter password:

BREAKING CHANGE
The old behavior requires a user to type --user and --password parameters for authentication. This change makes --password optional.

This behavior provides an extra security to users who do not want to type the password in plaintext in the console. The Enter password: prompt will not echo the password.

Testing done

Describe the testing strategy. Unit and integration tests are expected for any behavior changes.

  • Added unit tests for the Options
  • Tested manually

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@spena spena requested a review from a team December 16, 2019 22:32
@spena spena self-assigned this Dec 16, 2019
Copy link
Contributor

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except this isn't a breaking change since the old functionality (of passing username and password) is still supported, so we should remove the "BREAKING CHANGE:" section from the PR description/commit body.

@@ -67,6 +69,11 @@ public static void main(final String[] args) throws IOException {
System.exit(-1);
}

// ask for password if not set through command parameters
if (!options.getUserName().isEmpty() && !options.isPasswordSet()) {
options.setPassword(readPassword());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a unit test for this functionality?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any tests cases that verify the ksql command using parameters. The KsqlTest uses mocks and executes ksql.run() directly.

I tried using unit tests, but there are a few static classes used in the main class. I could reorganize the code to set stubs, but how do I set stubs or mocks on static classes?

Do you know if there are tests that verify ksql commands are executed using the cli?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if there are tests that verify ksql commands are executed using the cli?

Have you looked at the ones in https://github.com/confluentinc/ksql/blob/master/ksql-cli/src/test/java/io/confluent/ksql/cli/CliTest.java? Not exactly what you're looking for but many come close.

@@ -49,4 +49,21 @@ public void shouldReturnEmptyOptionWhenUserAndPassNotPresent() throws Exception
assertFalse(options.getUserNameAndPassword().isPresent());
}

@Test
public void shouldReturnFalseIfPasswordIsNull() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename to shouldReturnPasswordNotSetIfPasswordIsNull() or something similar to clarify what's returning false, and similarly for the other new tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@spena spena force-pushed the ask_password_console branch from fe396cb to 62595b3 Compare January 10, 2020 16:19
@spena spena force-pushed the ask_password_console branch from 62595b3 to 10854c0 Compare January 13, 2020 14:41
@spena
Copy link
Member Author

spena commented Jan 13, 2020

Jenkins is failing with unrelated changes to this code. The build and tests passed, but some packaging errors, like [ERROR] Unknown packaging: bundle @ line 6, column 16 are failing. They're the same errors as other PRs that have happened since last week.

I will merge this PR for now.

@spena spena merged commit 7a83bbf into confluentinc:master Jan 13, 2020
@spena spena deleted the ask_password_console branch January 13, 2020 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants