rspec/rules/S2647/python/rule.adoc

55 lines
1.6 KiB
Plaintext
Raw Normal View History

2020-06-30 12:48:07 +02:00
include::../description.adoc[]
== Noncompliant Code Example
https://docs.python.org/3/library/urllib.request.html[urllib.request] library:
2020-06-30 12:48:07 +02:00
----
import urllib.request
authenticationHandler = urllib.request.HTTPBasicAuthHandler() # Noncompliant
authenticationHandler.add_password(None,
'http://www.sonarsource.com/',
'sonaruser',
'secretpass1!')
opener = urllib.request.build_opener(authenticationHandler)
urllib.request.install_opener(opener)
urllib.request.urlopen('http://www.sonarsource.com/credential.html')
----
https://httplib2.readthedocs.io/en/latest/[httplib2] library:
2020-06-30 12:48:07 +02:00
----
import httplib2
conn = httplib2.Http(".cache")
conn.add_credentials('sonaruser', 'secretpass1!')
response, content = conn.request("http://www.sonarsource.com/rest/path", "GET") # Noncompliant
----
https://requests.readthedocs.io/en/master/[requests] library:
2020-06-30 12:48:07 +02:00
----
import requests
conn = requests.get('http://www.sonarsounce.com/rest/path', auth=('sonaruser', 'secretpass1!')) # Noncompliant
----
https://docs.python.org/3/library/http.client.html[http.client] library:
2020-06-30 12:48:07 +02:00
----
from http.client import HTTPConnection
from base64 import b64encode
conn = HTTPConnection('www.sonarsource.com')
credential = b64encode(b'sonaruser:secretpass1!').decode('ascii')
conn.request('GET', '/', headers={'Authorization': 'Basic %s' % credential}) # Noncompliant
----
include::../see.adoc[]
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::rspecator-view[]