Skip to content

Commit

Permalink
Support new auth method introduced in 6.43
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Kostka authored Jun 16, 2018
1 parent 8ea73d4 commit 5b685f3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ install:
script:
- pylama
- wget --quiet netng.pl/routeros_test_images/routeros_6.33.3.qcow2 -O images/routeros_6.33.3.qcow2
- wget --quiet netng.pl/routeros_test_images/routeros_6.43rc21.qcow2 -O images/routeros_6.43rc21.qcow2
- py.test --pylama
deploy:
provider: pypi
Expand Down
5 changes: 3 additions & 2 deletions images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ qemu-system-i386 \
-cdrom ISO_FILE.iso \
-vnc :3
```
Install every package except:
- kvm

* Install every package except `kvm`
* Add `dhcp-client` on `ether1`
14 changes: 10 additions & 4 deletions librouteros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ def connect(host, username, password, **kwargs):
api = arguments['subclass'](protocol=protocol)

try:
sentence = api('/login')
# First send dummy credentials to know if we get a =ret= back.
# This way we know if it is a pre 6.43 auth method or not.
sentence = api('/login', **{'name': 'dummy_user', 'password': 'dummy_password'})
token = sentence[0]['ret']
encoded = encode_password(token, password)
api('/login', **{'name': username, 'response': encoded})
except (ConnectionError, TrapError, FatalError, MultiTrapError):
except (TrapError, MultiTrapError):
# Login failed so use 6.43 auth method.
api('/login', **{'name': username, 'password': password})
except (ConnectionError, FatalError):
transport.close()
raise
else:
# We got =ret= so use pre 6.43 auth method.
api('/login', **{'name': username, 'response': encode_password(token, password)})

return api

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def api_session():
raise librouteros.ConnectionError('could not connect to device')


@pytest.fixture(scope='session')
@pytest.fixture(scope='session', params=('6.33.3', '6.43rc21'))
def disk_image(request):
"""Create a temporary disk image backed by original one."""
img = NamedTemporaryFile()
Expand All @@ -32,7 +32,7 @@ def disk_image(request):
'qemu-img', 'create',
'-f', 'qcow2',
# Path to backing file must be absolute or relative to new image
'-b', str(py.path.local().join('images/routeros_6.33.3.qcow2')),
'-b', str(py.path.local().join('images/routeros_{}.qcow2'.format(request.param))),
img.name,
]
check_call(cmd, stdout=DEV_NULL)
Expand Down

0 comments on commit 5b685f3

Please sign in to comment.