Skip to content

Commit

Permalink
AL-131 Add streaming read operation
Browse files Browse the repository at this point in the history
 - Adds SFTP server container to docker compose
 - Adds lines for testing read() operations
  • Loading branch information
cccs-samp committed Dec 18, 2020
1 parent 9246b4a commit a3e3354
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 1 addition & 2 deletions assemblyline/filestore/transport/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def put(self, dst_path, content):
except ResourceExistsError:
pass

# TODO: Create an extension of the base class TransportFile

class TransportReadStreamAzure(TransportReadStream):
def __init__(self, streamFile):
Expand All @@ -171,4 +170,4 @@ def close(self):
pass

def read(self, chunk_size=-1):
return next(self.file)
return next(self.file)
8 changes: 7 additions & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ services:
ports:
- '21:21'
- '20:20'
- '21100-21110:21100-21110'
- '21100-21110:21100-21110'

sftpServer:
image: atmoz/sftp
ports:
- '2222:22'
command: sftp_test_user:password:1001::test
13 changes: 11 additions & 2 deletions test/test_filestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_http():
httpObject = fs.read('assemblyline')
assert httpObject.read(chunk_size=32) is not None


def test_https():
"""
Test HTTPS FileStore by fetching the assemblyline page on
Expand All @@ -53,22 +54,28 @@ def test_https():
# Rebex test server.
# """
# fs = FileStore('sftp://demo:[email protected]')
# # fs = FileStore('sftp://sftp_test_user:password@localhost:2222')
# # fs.upload('readme.txt', 'readme.txt')
# assert fs.exists('readme.txt') != []
# assert fs.get('readme.txt') is not None
# sftpfile = fs.read('readme.txt')
# assert sftpfile.read() is not None


def test_ftp():
"""
Test FTP FileStore by fetching the readme.txt file from
Rebex test server.
containerized server.
"""
fs = FileStore('ftp://al_test_user:password@localhost')

fs.upload('readme.txt', 'readme.txt')
# fs = FileStore('ftp://demo:[email protected]')
assert fs.exists('readme.txt') != []
assert fs.get('readme.txt') is not None
ftpfile = fs.read('readme.txt')
assert ftpfile.read() is not None
fs.delete('readme.txt')
assert fs.exists('readme.txt') == []


# def test_ftps():
Expand All @@ -79,6 +86,8 @@ def test_ftp():
# fs = FileStore('ftps://demo:[email protected]')
# assert fs.exists('readme.txt') != []
# assert fs.get('readme.txt') is not None
# ftpsfile = fs.read('readme.txt')
# assert ftpsfile.read() is not None


def test_file():
Expand Down

0 comments on commit a3e3354

Please sign in to comment.