2020-06-30 12:48:07 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
https://docs.python.org/3/library/urllib.request.html[urllib.request] library:
|
2020-06-30 14:49:38 +02:00
|
|
|
|
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')
|
|
|
|
----
|
2020-12-21 15:38:52 +01:00
|
|
|
https://httplib2.readthedocs.io/en/latest/[httplib2] library:
|
2020-06-30 14:49:38 +02:00
|
|
|
|
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
|
|
|
|
----
|
2020-12-21 15:38:52 +01:00
|
|
|
https://requests.readthedocs.io/en/master/[requests] library:
|
2020-06-30 14:49:38 +02:00
|
|
|
|
2020-06-30 12:48:07 +02:00
|
|
|
----
|
|
|
|
import requests
|
|
|
|
|
|
|
|
conn = requests.get('http://www.sonarsounce.com/rest/path', auth=('sonaruser', 'secretpass1!')) # Noncompliant
|
|
|
|
----
|
2020-12-21 15:38:52 +01:00
|
|
|
https://docs.python.org/3/library/http.client.html[http.client] library:
|
2020-06-30 14:49:38 +02:00
|
|
|
|
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[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|