Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
177fa083
Kaydet (Commit)
177fa083
authored
Nis 16, 2019
tarafından
Oleh Mykytiuk
Kaydeden (comit)
Mariusz Felisiak
Nis 18, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #30370 -- Added dbshell support for client TLS certificates on PostgreSQL.
üst
d87bd29c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
7 deletions
+44
-7
client.py
django/db/backends/postgresql/client.py
+12
-0
3.0.txt
docs/releases/3.0.txt
+2
-0
test_postgresql.py
tests/dbshell/test_postgresql.py
+30
-7
No files found.
django/db/backends/postgresql/client.py
Dosyayı görüntüle @
177fa083
...
...
@@ -17,6 +17,10 @@ class DatabaseClient(BaseDatabaseClient):
dbname
=
conn_params
.
get
(
'database'
,
''
)
user
=
conn_params
.
get
(
'user'
,
''
)
passwd
=
conn_params
.
get
(
'password'
,
''
)
sslmode
=
conn_params
.
get
(
'sslmode'
,
''
)
sslrootcert
=
conn_params
.
get
(
'sslrootcert'
,
''
)
sslcert
=
conn_params
.
get
(
'sslcert'
,
''
)
sslkey
=
conn_params
.
get
(
'sslkey'
,
''
)
if
user
:
args
+=
[
'-U'
,
user
]
...
...
@@ -30,6 +34,14 @@ class DatabaseClient(BaseDatabaseClient):
subprocess_env
=
os
.
environ
.
copy
()
if
passwd
:
subprocess_env
[
'PGPASSWORD'
]
=
str
(
passwd
)
if
sslmode
:
subprocess_env
[
'PGSSLMODE'
]
=
str
(
sslmode
)
if
sslrootcert
:
subprocess_env
[
'PGSSLROOTCERT'
]
=
str
(
sslrootcert
)
if
sslcert
:
subprocess_env
[
'PGSSLCERT'
]
=
str
(
sslcert
)
if
sslkey
:
subprocess_env
[
'PGSSLKEY'
]
=
str
(
sslkey
)
try
:
# Allow SIGINT to pass to psql to abort queries.
signal
.
signal
(
signal
.
SIGINT
,
signal
.
SIG_IGN
)
...
...
docs/releases/3.0.txt
Dosyayı görüntüle @
177fa083
...
...
@@ -172,6 +172,8 @@ Management Commands
* :option:`showmigrations --list` now shows the applied datetimes when
``--verbosity`` is 2 and above.
* On PostgreSQL, :djadmin:`dbshell` now supports client-side TLS certificates.
Migrations
~~~~~~~~~~
...
...
tests/dbshell/test_postgresql.py
Dosyayı görüntüle @
177fa083
...
...
@@ -14,15 +14,16 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
That function invokes the runshell command, while mocking
subprocess.run(). It returns a 2-tuple with:
- The command line list
- The
the value of the PGPASSWORD environment variable, or None
.
- The
dictionary of PG* environment variables, or {}
.
"""
def
_mock_subprocess_run
(
*
args
,
env
=
os
.
environ
,
**
kwargs
):
self
.
subprocess_args
=
list
(
*
args
)
self
.
pgpassword
=
env
.
get
(
'PGPASSWORD'
)
# PostgreSQL environment variables.
self
.
pg_env
=
{
key
:
env
[
key
]
for
key
in
env
if
key
.
startswith
(
'PG'
)}
return
subprocess
.
CompletedProcess
(
self
.
subprocess_args
,
0
)
with
mock
.
patch
(
'subprocess.run'
,
new
=
_mock_subprocess_run
):
DatabaseClient
.
runshell_db
(
dbinfo
)
return
self
.
subprocess_args
,
self
.
pg
password
return
self
.
subprocess_args
,
self
.
pg
_env
def
test_basic
(
self
):
self
.
assertEqual
(
...
...
@@ -34,7 +35,7 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
'port'
:
'444'
,
}),
(
[
'psql'
,
'-U'
,
'someuser'
,
'-h'
,
'somehost'
,
'-p'
,
'444'
,
'dbname'
],
'somepassword'
,
{
'PGPASSWORD'
:
'somepassword'
}
,
)
)
...
...
@@ -47,7 +48,29 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
'port'
:
'444'
,
}),
(
[
'psql'
,
'-U'
,
'someuser'
,
'-h'
,
'somehost'
,
'-p'
,
'444'
,
'dbname'
],
None
,
{},
)
)
def
test_ssl_certificate
(
self
):
self
.
assertEqual
(
self
.
_run_it
({
'database'
:
'dbname'
,
'user'
:
'someuser'
,
'host'
:
'somehost'
,
'port'
:
'444'
,
'sslmode'
:
'verify-ca'
,
'sslrootcert'
:
'root.crt'
,
'sslcert'
:
'client.crt'
,
'sslkey'
:
'client.key'
,
}),
(
[
'psql'
,
'-U'
,
'someuser'
,
'-h'
,
'somehost'
,
'-p'
,
'444'
,
'dbname'
],
{
'PGSSLCERT'
:
'client.crt'
,
'PGSSLKEY'
:
'client.key'
,
'PGSSLMODE'
:
'verify-ca'
,
'PGSSLROOTCERT'
:
'root.crt'
,
},
)
)
...
...
@@ -61,7 +84,7 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
'port'
:
'444'
,
}),
(
[
'psql'
,
'-U'
,
'some:user'
,
'-h'
,
'::1'
,
'-p'
,
'444'
,
'dbname'
],
'some:password'
,
{
'PGPASSWORD'
:
'some:password'
}
,
)
)
...
...
@@ -77,7 +100,7 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
'port'
:
'444'
,
}),
(
[
'psql'
,
'-U'
,
username
,
'-h'
,
'somehost'
,
'-p'
,
'444'
,
'dbname'
],
password
,
{
'PGPASSWORD'
:
password
}
,
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment