Skip to content

Commit

Permalink
Cleanup cpp dir Python code (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Jan 19, 2024
1 parent ba7f879 commit ef3505e
Show file tree
Hide file tree
Showing 43 changed files with 1,659 additions and 712 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Python lint and format

on:
workflow_dispatch:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]

jobs:
ruff-lint:
name: Ruff check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install SwiftLints
run: pip install ruff

- name: Run Ruff
run: ruff check 'cpp' --ignore E402
1 change: 1 addition & 0 deletions cpp/allTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "..", "scripts"))

from Util import runTestsWithPath
Expand Down
3 changes: 3 additions & 0 deletions cpp/test/Glacier2/attack/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
# Copyright (c) ZeroC, Inc. All rights reserved.
#

from Glacier2Util import Glacier2TestSuite


Glacier2TestSuite(__name__, routerProps={"Glacier2.RoutingTable.MaxSize": 10})
31 changes: 23 additions & 8 deletions cpp/test/Glacier2/dynamicFiltering/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@
# Note: we limit the send buffer size with Ice.TCP.SndSize, the
# test relies on send() blocking
#
def routerProps(process, current): return {
'Glacier2.SessionManager': 'SessionManager:{0}'.format(current.getTestEndpoint(0)),
'Glacier2.PermissionsVerifier': 'Glacier2/NullPermissionsVerifier',
'Ice.Default.Locator': 'locator:{0}'.format(current.getTestEndpoint(1)),
}
from Glacier2Util import Glacier2Router, Glacier2TestSuite
from Util import ClientServerTestCase, Server


Glacier2TestSuite(__name__,
testcases=[ClientServerTestCase(servers=[Glacier2Router(props=routerProps, passwords=None),
Server(readyCount=3)])])
def routerProps(process, current):
return {
"Glacier2.SessionManager": "SessionManager:{0}".format(
current.getTestEndpoint(0)
),
"Glacier2.PermissionsVerifier": "Glacier2/NullPermissionsVerifier",
"Ice.Default.Locator": "locator:{0}".format(current.getTestEndpoint(1)),
}


Glacier2TestSuite(
__name__,
testcases=[
ClientServerTestCase(
servers=[
Glacier2Router(props=routerProps, passwords=None),
Server(readyCount=3),
]
)
],
)
57 changes: 42 additions & 15 deletions cpp/test/Glacier2/hashpassword/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
# Copyright (c) ZeroC, Inc. All rights reserved.
#

class Glacier2HashPasswordTestCase(ClientTestCase):
import os
import sys
from Util import ClientTestCase, TestSuite, toplevel, run

def runClientSide(self, current):

class Glacier2HashPasswordTestCase(ClientTestCase):
def runClientSide(self, current):
import passlib.hash

hashpassword = os.path.join(toplevel, "scripts", "icehashpassword.py")
Expand All @@ -15,25 +18,42 @@ def runClientSide(self, current):

def test(b):
if not b:
raise RuntimeError('test assertion failed')
raise RuntimeError("test assertion failed")

def hashPasswords(password, args=""):
return run('"%s" "%s" %s' % (sys.executable, hashpassword, args),
stdin=(password + "\r\n").encode('UTF-8'),
stdinRepeat=False)
return run(
'"%s" "%s" %s' % (sys.executable, hashpassword, args),
stdin=(password + "\r\n").encode("UTF-8"),
stdinRepeat=False,
)

if usePBKDF2:

current.write("Testing PBKDF2 crypt passwords...")

test(passlib.hash.pbkdf2_sha256.verify("abc123", hashPasswords("abc123")))
test(not passlib.hash.pbkdf2_sha256.verify("abc123", hashPasswords("abc")))

test(passlib.hash.pbkdf2_sha1.verify("abc123", hashPasswords("abc123", "-d sha1")))
test(not passlib.hash.pbkdf2_sha1.verify("abc123", hashPasswords("abc", "-d sha1")))

test(passlib.hash.pbkdf2_sha512.verify("abc123", hashPasswords("abc123", "-d sha512")))
test(not passlib.hash.pbkdf2_sha512.verify("abc123", hashPasswords("abc", "-d sha512")))
test(
passlib.hash.pbkdf2_sha1.verify(
"abc123", hashPasswords("abc123", "-d sha1")
)
)
test(
not passlib.hash.pbkdf2_sha1.verify(
"abc123", hashPasswords("abc", "-d sha1")
)
)

test(
passlib.hash.pbkdf2_sha512.verify(
"abc123", hashPasswords("abc123", "-d sha512")
)
)
test(
not passlib.hash.pbkdf2_sha512.verify(
"abc123", hashPasswords("abc", "-d sha512")
)
)

#
# Now use custom rounds
Expand All @@ -56,14 +76,21 @@ def hashPasswords(password, args=""):
current.writeln("ok")

elif useCryptExt:

current.write("Testing Linux crypt passwords...")

test(passlib.hash.sha512_crypt.verify("abc123", hashPasswords("abc123")))
test(not passlib.hash.sha512_crypt.verify("abc123", hashPasswords("abc")))

test(passlib.hash.sha256_crypt.verify("abc123", hashPasswords("abc123", "-d sha256")))
test(not passlib.hash.sha256_crypt.verify("abc123", hashPasswords("abc", "-d sha256")))
test(
passlib.hash.sha256_crypt.verify(
"abc123", hashPasswords("abc123", "-d sha256")
)
)
test(
not passlib.hash.sha256_crypt.verify(
"abc123", hashPasswords("abc", "-d sha256")
)
)

#
# Now use custom rounds
Expand Down
33 changes: 18 additions & 15 deletions cpp/test/Glacier2/override/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
# Note: we limit the send buffer size with Ice.TCP.SndSize, the
# test relies on send() blocking
#
from Glacier2Util import Glacier2TestSuite


routerProps = {
'Ice.Warn.Dispatch': '0',
'Ice.Warn.Connections': '0',
'Ice.TCP.SndSize': '100000',
'Ice.ThreadPool.Server.Serialize': '1',
'Ice.ThreadPool.Client.Serialize': '1',
'Glacier2.Filter.Category.Accept': '"c"',
'Glacier2.PermissionsVerifier': 'Glacier2/NullPermissionsVerifier',
'Glacier2.Client.ForwardContext': '1',
'Glacier2.Client.ACM.Timeout': '"30"',
'Glacier2.Client.Trace.Override': '0',
'Glacier2.Client.Trace.Request': '0',
'Glacier2.Server.Trace.Override': '0',
'Glacier2.Server.Trace.Request': '0',
'Glacier2.Client.Buffered=1 --Glacier2.Server.Buffered': '1',
'Glacier2.Client.SleepTime=50 --Glacier2.Server.SleepTime': '50',
"Ice.Warn.Dispatch": "0",
"Ice.Warn.Connections": "0",
"Ice.TCP.SndSize": "100000",
"Ice.ThreadPool.Server.Serialize": "1",
"Ice.ThreadPool.Client.Serialize": "1",
"Glacier2.Filter.Category.Accept": '"c"',
"Glacier2.PermissionsVerifier": "Glacier2/NullPermissionsVerifier",
"Glacier2.Client.ForwardContext": "1",
"Glacier2.Client.ACM.Timeout": '"30"',
"Glacier2.Client.Trace.Override": "0",
"Glacier2.Client.Trace.Request": "0",
"Glacier2.Server.Trace.Override": "0",
"Glacier2.Server.Trace.Request": "0",
"Glacier2.Client.Buffered=1 --Glacier2.Server.Buffered": "1",
"Glacier2.Client.SleepTime=50 --Glacier2.Server.SleepTime": "50",
}

Glacier2TestSuite(__name__, routerProps=routerProps)
22 changes: 17 additions & 5 deletions cpp/test/Glacier2/sessionControl/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@
# Note: we limit the send buffer size with Ice.TCP.SndSize, the
# test relies on send() blocking
#
def routerProps(process, current): return {
'Glacier2.SessionManager': 'SessionManager:{0}'.format(current.getTestEndpoint(0)),
'Glacier2.PermissionsVerifier': 'Glacier2/NullPermissionsVerifier',
}
from Glacier2Util import Glacier2Router, Glacier2TestSuite
from Util import ClientServerTestCase, Server


Glacier2TestSuite(__name__, testcases=[ClientServerTestCase(servers=[Glacier2Router(props=routerProps), Server()])])
def routerProps(process, current):
return {
"Glacier2.SessionManager": "SessionManager:{0}".format(
current.getTestEndpoint(0)
),
"Glacier2.PermissionsVerifier": "Glacier2/NullPermissionsVerifier",
}


Glacier2TestSuite(
__name__,
testcases=[
ClientServerTestCase(servers=[Glacier2Router(props=routerProps), Server()])
],
)
54 changes: 40 additions & 14 deletions cpp/test/Glacier2/ssl/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,51 @@
# Copyright (c) ZeroC, Inc. All rights reserved.
#

def routerProps(process, current): return {
'Ice.Warn.Dispatch': '0',
'Glacier2.AddConnectionContext': '1',
'Glacier2.Client.Endpoints': '{0}:{1}'.format(current.getTestEndpoint(0, "tcp"), current.getTestEndpoint(1, "ssl")),
'Ice.Admin.Endpoints': current.getTestEndpoint(2, "tcp"),
'Glacier2.SessionManager': 'sessionmanager:{0}'.format(current.getTestEndpoint(3, "tcp")),
'Glacier2.PermissionsVerifier': 'verifier:{0}'.format(current.getTestEndpoint(3, "tcp")),
'Glacier2.SSLSessionManager': 'sslsessionmanager:{0}'.format(current.getTestEndpoint(3, "tcp")),
'Glacier2.SSLPermissionsVerifier': 'sslverifier:{0}'.format(current.getTestEndpoint(3, "tcp")),
}
from Glacier2Util import Glacier2Router, Glacier2TestSuite
from Util import Client, ClientServerTestCase, Server


def routerProps(process, current):
return {
"Ice.Warn.Dispatch": "0",
"Glacier2.AddConnectionContext": "1",
"Glacier2.Client.Endpoints": "{0}:{1}".format(
current.getTestEndpoint(0, "tcp"), current.getTestEndpoint(1, "ssl")
),
"Ice.Admin.Endpoints": current.getTestEndpoint(2, "tcp"),
"Glacier2.SessionManager": "sessionmanager:{0}".format(
current.getTestEndpoint(3, "tcp")
),
"Glacier2.PermissionsVerifier": "verifier:{0}".format(
current.getTestEndpoint(3, "tcp")
),
"Glacier2.SSLSessionManager": "sslsessionmanager:{0}".format(
current.getTestEndpoint(3, "tcp")
),
"Glacier2.SSLPermissionsVerifier": "sslverifier:{0}".format(
current.getTestEndpoint(3, "tcp")
),
}


#
# Always enable SSL for the Glacier2 router and client
#


def sslProps(process, current): return current.testcase.getMapping().getSSLProps(process, current)
def sslProps(process, current):
return current.testcase.getMapping().getSSLProps(process, current)


Glacier2TestSuite(__name__, routerProps=routerProps, options={"ipv6": [False]}, multihost=False,
testcases=[ClientServerTestCase(servers=[Glacier2Router(props=sslProps), Server()],
client=Client(props=sslProps))])
Glacier2TestSuite(
__name__,
routerProps=routerProps,
options={"ipv6": [False]},
multihost=False,
testcases=[
ClientServerTestCase(
servers=[Glacier2Router(props=sslProps), Server()],
client=Client(props=sslProps),
)
],
)
Loading

0 comments on commit ef3505e

Please sign in to comment.