Skip to content

Commit

Permalink
validate user ID and topic name on the client
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Mar 11, 2021
1 parent dc29e05 commit b2ee355
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tn-cli/tn-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from tn_globals import to_json

APP_NAME = "tn-cli"
APP_VERSION = "1.5.5"
APP_VERSION = "1.5.6"
PROTOCOL_VERSION = "0"
LIB_VERSION = pkg_resources.get_distribution("tinode_grpc").version
GRPC_VERSION = pkg_resources.get_distribution("grpcio").version
Expand Down Expand Up @@ -815,20 +815,28 @@ def serialize_cmd(string, id, args):
elif cmd.cmd == ".use":
if cmd.user != "unchanged":
if cmd.user:
tn_globals.DefaultUser = cmd.user
if len(cmd.user) > 3 and cmd.user.startswith("usr"):
tn_globals.DefaultUser = cmd.user
else:
stdoutln("Error: user ID '{}' is invalid".format(cmd.user))
else:
tn_globals.DefaultUser = None
stdoutln("Default user='" + cmd.user + "'")
stdoutln("Default user='{}'".format(tn_globals.DefaultUser))

if cmd.topic != "unchanged":
if cmd.topic:
tn_globals.DefaultTopic = cmd.topic
if cmd.topic[:3] in ['me', 'fnd', 'sys', 'usr', 'grp', 'chn']:
tn_globals.DefaultTopic = cmd.topic
else:
stdoutln("Error: topic '{}' is invalid".format(cmd.topic))
else:
tn_globals.DefaultTopic = None
stdoutln("Default topic='" + cmd.topic + "'")
stdoutln("Default topic='{}'".format(tn_globals.DefaultTopic))

return None, None

elif cmd.cmd == ".sleep":
stdoutln("Pausing for " + str(cmd.millis) + "ms...")
stdoutln("Pausing for {}ms...".format(cmd.millis))
time.sleep(cmd.millis/1000.)
return None, None

Expand Down

0 comments on commit b2ee355

Please sign in to comment.