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

Ability to flush buffer before expect #58

Open
dhubbard-ic opened this issue Oct 4, 2018 · 1 comment
Open

Ability to flush buffer before expect #58

dhubbard-ic opened this issue Oct 4, 2018 · 1 comment

Comments

@dhubbard-ic
Copy link

dhubbard-ic commented Oct 4, 2018

I have a use case where I believe the remaining buffer after a matched expect is tripping up my processing for next.

I'm using ExpectIt with SSHJ to handle password expiry. In this use case, against OpenSSH, when the initial connect is made "passwd" is activated server-side.

The issue (for me) is that passwd issues error and instructions lines like:

BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
New password:

Currently I am matching on "BAD PASSWORD" so that I can feed back info to the user - however if I feed in next entered password in then password responds with

Retype new password:

...which is reasonable, but at this point the buffer is:

The password fails the dictionary check - it is based on a dictionary word
New password:
Retype new password:

...(i.e. with the "BAD PASSWORD" removed and the left over "New password" indicates first password - whereas "Retype new password" indicates second.

So is it possible to add a "flush()" method to allow controlling the buffer before sending the password? I have done this in a cloned version using the following - which works well, but I may not have considered all threading implications and attributes.

In SingleInputExpect

    void flush() {
        try {
            ByteBuffer byteBuffer = ByteBuffer.allocate(BUFFER_SIZE);
            int len = source.read(byteBuffer);
            buffer.delete(0, buffer.length());
        } catch (IOException ex) {
            LOG.warning("Error reading source");
        }
    }

and in ExpectImpl

    @Override
    public void flush() {
        SingleInputExpect[] inputs = getInputs();
        for (SingleInputExpect input : inputs) {
            input.flush();
        }
    }

@agavrilov76
Copy link
Owner

Can you wait for "Retype new password:" after sending the new password on a response to "New password:"?

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

No branches or pull requests

2 participants