isinstance for SASL types, so EXTERNAL doesn't have blank user/pass
This commit is contained in:
parent
067fbbc531
commit
f18efda31b
2 changed files with 15 additions and 19 deletions
|
@ -2,23 +2,19 @@ from typing import Optional
|
|||
from dataclasses import dataclass
|
||||
|
||||
class SASLParams(object):
|
||||
def __init__(self,
|
||||
mechanism: str,
|
||||
username: str="",
|
||||
password: str=""):
|
||||
self.mechanism = mechanism.upper()
|
||||
self.username = username
|
||||
self.password = password
|
||||
mechanism: str
|
||||
|
||||
class SASLUserPass(SASLParams):
|
||||
def __init__(self, username: str, password: str):
|
||||
super().__init__("USERPASS", username, password)
|
||||
class SASLSCRAM(SASLParams):
|
||||
def __init__(self, username: str, password: str):
|
||||
super().__init__("SCRAM", username, password)
|
||||
@dataclass
|
||||
class _SASLUserPass(SASLParams):
|
||||
username: str
|
||||
password: str
|
||||
|
||||
class SASLUserPass(_SASLUserPass):
|
||||
mechanism = "USERPASS"
|
||||
class SASLSCRAM(_SASLUserPass):
|
||||
mechanism = "SCRAM"
|
||||
class SASLExternal(SASLParams):
|
||||
def __init__(self):
|
||||
super().__init__("EXTERNAL")
|
||||
mechanism = "EXTERNAL"
|
||||
|
||||
@dataclass
|
||||
class STSPolicy(object):
|
||||
|
|
|
@ -6,7 +6,7 @@ from ircstates.numerics import *
|
|||
|
||||
from .matching import ResponseOr, Responses, Response, ANY
|
||||
from .contexts import ServerContext
|
||||
from .params import SASLParams
|
||||
from .params import SASLParams, SASLUserPass, SASLSCRAM, SASLExternal
|
||||
from .scram import SCRAMContext
|
||||
|
||||
SASL_SCRAM_MECHANISMS = [
|
||||
|
@ -47,11 +47,11 @@ def _b64db(s: str) -> bytes:
|
|||
|
||||
class SASLContext(ServerContext):
|
||||
async def from_params(self, params: SASLParams) -> SASLResult:
|
||||
if params.mechanism == "USERPASS":
|
||||
if isinstance(params, SASLUserPass):
|
||||
return await self.userpass(params.username, params.password)
|
||||
elif params.mechanism == "SCRAM":
|
||||
elif isinstance(params, SASLSCRAM):
|
||||
return await self.scram(params.username, params.password)
|
||||
elif params.mechanism == "EXTERNAL":
|
||||
elif isinstance(params, SASLExternal):
|
||||
return await self.external()
|
||||
else:
|
||||
raise SASLUnknownMechanismError(
|
||||
|
|
Loading…
Reference in a new issue