Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SocketIOUser] - I have provided the code to turn off the SSL certification but still, I'm getting an SSL certification error #2144

Closed
balaji2711 opened this issue Jul 29, 2022 · 7 comments
Labels

Comments

@balaji2711
Copy link

Hi All,

I have provided the code to turn off the SSL certification but still, I'm getting an SSL certification error. Please find the below code -

class TestLocust(SocketIOUser):

@task
def my_task(self):
    self.connect("wss://javascript.info/article/websocket/demo/hello", header=["XMLDecode", {"cert_req": ssl.CERT_NONE}])
    self.send('hello["subscribe",{"url":"/article/websocket/demo/hello","sendInitialUpdate": true, "message":"helloworld"}]')     

def on_message(self, message):
    self.my_value = message

Error Message:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)

Any help or suggestion would be appreciated. Thanks in advance.

@balaji2711 balaji2711 added the bug label Jul 29, 2022
@balaji2711
Copy link
Author

I'm using the below version, - locust 2.10.1

@cyberw
Copy link
Collaborator

cyberw commented Jul 29, 2022

open() is pretty much just a wrapper around websocket.create_connection(), so maybe check its documentation?

@balaji2711
Copy link
Author

balaji2711 commented Jul 29, 2022

Hi @cyberw,

I don't see open() in a WebSocket class. And I don't see it's documented anywhere.
Please find the below create_connection() from WebSocket class.

WebSocket.create_connection() is accepting the sslopt parameters (Refer the highlighted lines below) but SocketIOUser.connect() is not accepting the sslopt. Getting the below error message when I pass the sslopt parameters

TypeError: SocketIOUser.connect() got an unexpected keyword argument 'sslopt'

def create_connection(url, timeout=None, class_=WebSocket, **options):
"""
Parameters
----------
class_: class
class to instantiate when creating the connection. It has to implement
settimeout and connect. It's init should be compatible with
WebSocket.init, i.e. accept all of it's kwargs.
header: list or dict
custom http header list or dict.
cookie: str
Cookie value.
origin: str
custom origin url.
suppress_origin: bool
suppress outputting origin header.
host: str
custom host header string.
timeout: int or float
socket timeout time. This value could be either float/integer.
If set to None, it uses the default_timeout value.
http_proxy_host: str
HTTP proxy host name.
http_proxy_port: str or int
HTTP proxy port. If not set, set to 80.
http_no_proxy: list
Whitelisted host names that don't use the proxy.
http_proxy_auth: tuple
HTTP proxy auth information. tuple of username and password. Default is None.
enable_multithread: bool
Enable lock for multithread.
redirect_limit: int
Number of redirects to follow.
sockopt: tuple
Values for socket.setsockopt.
sockopt must be a tuple and each element is an argument of sock.setsockopt.
sslopt: dict
Optional dict object for ssl socket options. See FAQ for details.
subprotocols: list
List of available subprotocols. Default is None.

skip_utf8_validation: bool
Skip utf8 validation.
socket: socket
Pre-initialized stream socket.
"""
sockopt = options.pop("sockopt", [])
sslopt = options.pop("sslopt", {})
fire_cont_frame = options.pop("fire_cont_frame", False)
enable_multithread = options.pop("enable_multithread", True)
skip_utf8_validation = options.pop("skip_utf8_validation", False)
websock = class_(sockopt=sockopt, sslopt=sslopt,
fire_cont_frame=fire_cont_frame,
enable_multithread=enable_multithread,
skip_utf8_validation=skip_utf8_validation, **options)
websock.settimeout(timeout if timeout is not None else getdefaulttimeout())
websock.connect(url, **options)
return websock

Please note: I'm able to run my code with websocket.create_connection() not with SocketIOUser.connect()

Kindly change the code to accept sslopt and subprotocols as well.

@cyberw
Copy link
Collaborator

cyberw commented Jul 29, 2022

@cyberw
Copy link
Collaborator

cyberw commented Jul 29, 2022

If you want to change it to also forward other arguments, please make a PR.

balaji2711 added a commit to balaji2711/locust-plugins that referenced this issue Jul 29, 2022
Based on the comments from @cyberw, I have fixed the issue - locustio/locust#2144. Please find the below code for the file - locust-plugins/locust_plugins/users/socketio.py. Please review and commit the code accordingly.
@balaji2711
Copy link
Author

Hi @cyberw,

I have raised the PR. Please review and merge the code.

@cyberw
Copy link
Collaborator

cyberw commented Jul 29, 2022

Fixed in locust-plugins 2.6.9

@cyberw cyberw closed this as completed Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants