Skip to content

Commit

Permalink
Merge pull request #344 from jborean93/py311
Browse files Browse the repository at this point in the history
Remove inspect method for Python 3.11
  • Loading branch information
jborean93 committed Apr 14, 2022
2 parents 9fe56fd + 4a39be0 commit de7ac17
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 88 deletions.
92 changes: 50 additions & 42 deletions .github/workflows/ci.yml
Expand Up @@ -8,9 +8,9 @@ on:
branches:
- master

env:
WINRM_USERNAME: pywinrm-test
WINRM_PASSWORD: Password123!
# env:
# WINRM_USERNAME: pywinrm-test
# WINRM_PASSWORD: Password123!

jobs:
test:
Expand All @@ -28,6 +28,7 @@ jobs:
- 3.7
- 3.8
- 3.9
- '3.10'
- pypy-2.7
- pypy-3.7
arch:
Expand Down Expand Up @@ -57,26 +58,33 @@ jobs:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.arch }}

- name: set up Windows integration tests
if: startsWith(matrix.os, 'windows')
shell: pwsh
run: |
Write-Host 'Create local admin user'
$userParams = @{
Name = $env:WINRM_USERNAME
Password = (ConvertTo-SecureString -AsPlainText -Force -String $env:WINRM_PASSWORD)
AccountNeverExpires = $true
PasswordNeverExpires = $true
}
$null = New-LocalUser @userParams
Add-LocalGroupMember -Group Administrators -Member $userParams.Name
Write-Host 'Setting up WinRM settings'
Enable-PSRemoting -Force -SkipNetworkProfileCheck
Enable-WSManCredSSP -Role Server -Force
Set-Item WSMan:\localhost\Service\Auth\Basic $true
Set-Item WSMan:\localhost\Service\Auth\CredSSP $true
Set-Item WSMan:\localhost\Service\AllowUnencrypted $true
# - name: Remove extra modules to speed up PowerShell startup module due to slow WinRM issue
# if: startsWith(matrix.os, 'windows')
# shell: bash
# run: |
# rm -rf "/c/Program Files/WindowsPowerShell/Modules/AWSPowerShell"
# rm -rf "/c/Program Files/WindowsPowerShell/Modules/Microsoft.Graph*"

# - name: set up Windows integration tests
# if: startsWith(matrix.os, 'windows')
# shell: pwsh
# run: |
# Write-Host 'Create local admin user'
# $userParams = @{
# Name = $env:WINRM_USERNAME
# Password = (ConvertTo-SecureString -AsPlainText -Force -String $env:WINRM_PASSWORD)
# AccountNeverExpires = $true
# PasswordNeverExpires = $true
# }
# $null = New-LocalUser @userParams
# Add-LocalGroupMember -Group Administrators -Member $userParams.Name

# Write-Host 'Setting up WinRM settings'
# Enable-PSRemoting -Force -SkipNetworkProfileCheck
# Enable-WSManCredSSP -Role Server -Force
# Set-Item WSMan:\localhost\Service\Auth\Basic $true
# Set-Item WSMan:\localhost\Service\Auth\CredSSP $true
# Set-Item WSMan:\localhost\Service\AllowUnencrypted $true

- name: set up Linux dependencies
if: startsWith(matrix.os, 'ubuntu')
Expand All @@ -103,30 +111,30 @@ jobs:
if: startsWith(matrix.os, 'windows')
run: |
pytest -v --flake8 --cov=winrm --cov-report=term-missing winrm/tests/
env:
WINRM_TRANSPORT: basic
WINRM_ENDPOINT: http://localhost:5985/wsman
# env:
# WINRM_TRANSPORT: basic
# WINRM_ENDPOINT: http://localhost:5985/wsman

- name: upload coverage data
if: "!endsWith(matrix.python-version, '2.7')" # Uses an older coverals version that doesn't support GHA
run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: run integration with NTLM
if: startsWith(matrix.os, 'windows')
run: |
Set-Item WSMan:\localhost\Service\AllowUnencrypted $false
py.test -v winrm/tests/test_integration_protocol.py winrm/tests/test_integration_session.py
env:
WINRM_TRANSPORT: ntlm
WINRM_ENDPOINT: http://localhost:5985/wsman
# - name: run integration with NTLM
# if: startsWith(matrix.os, 'windows')
# run: |
# Set-Item WSMan:\localhost\Service\AllowUnencrypted $false
# py.test -v winrm/tests/test_integration_protocol.py winrm/tests/test_integration_session.py
# env:
# WINRM_TRANSPORT: ntlm
# WINRM_ENDPOINT: http://localhost:5985/wsman

- name: run integration with CredSSP
if: startsWith(matrix.os, 'windows')
run: |
Set-Item WSMan:\localhost\Service\AllowUnencrypted $false
py.test -v winrm/tests/test_integration_protocol.py winrm/tests/test_integration_session.py
env:
WINRM_TRANSPORT: credssp
WINRM_ENDPOINT: http://localhost:5985/wsman
# - name: run integration with CredSSP
# if: startsWith(matrix.os, 'windows')
# run: |
# Set-Item WSMan:\localhost\Service\AllowUnencrypted $false
# py.test -v winrm/tests/test_integration_protocol.py winrm/tests/test_integration_session.py
# env:
# WINRM_TRANSPORT: credssp
# WINRM_ENDPOINT: http://localhost:5985/wsman
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
### Version 0.4.3
- Fix invalid regex escape sequences.
- Decoding CLIXML failures for `run_ps` will create a `UserWarning` rather than printing the warning.
- Remove usage of deprecated Python API to support Python 3.11

### Version 0.4.2
- Dropped Python 3.5 from support matrix as it is EOL.
Expand Down
7 changes: 3 additions & 4 deletions requirements-test.txt
@@ -1,6 +1,5 @@
# this assumes the base requirements have been satisfied via setup.py
# pin specific versions to keep things more stable over time; only pin sub-packages if necessary
pytest==4.4.2
pytest-cov==2.7.1
pytest
pytest-cov
pytest-flake8==1.0.7
mock==3.0.5
mock
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -23,7 +23,7 @@
license='MIT license',
packages=find_packages(),
package_data={'winrm.tests': ['*.ps1']},
install_requires=['xmltodict', 'requests>=2.9.1', 'requests_ntlm>=0.3.0', 'six'],
install_requires=['xmltodict', 'requests>=2.9.1', 'requests_ntlm>=1.1.0', 'six'],
extras_require={
'credssp': ['requests-credssp>=1.0.0'],
'kerberos:sys_platform=="win32"': ['winkerberos>=0.5.0'],
Expand All @@ -44,6 +44,7 @@
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Clustering',
Expand Down
49 changes: 8 additions & 41 deletions winrm/transport.py
@@ -1,7 +1,6 @@
from __future__ import unicode_literals
import sys
import os
import inspect
import requests
import requests.auth
import warnings
Expand Down Expand Up @@ -228,12 +227,10 @@ def build_session(self):

if self.auth_method == 'kerberos':
if not HAVE_KERBEROS:
raise WinRMError("requested auth method is kerberos, but requests_kerberos is not installed")
raise WinRMError("requested auth method is kerberos, but pykerberos is not installed")

man_args = dict(
session.auth = HTTPKerberosAuth(
mutual_authentication=REQUIRED,
)
opt_args = dict(
delegate=self.kerberos_delegation,
force_preemptive=True,
principal=self.username,
Expand All @@ -242,8 +239,6 @@ def build_session(self):
service=self.service,
send_cbt=self.send_cbt
)
kerb_args = self._get_args(man_args, opt_args, HTTPKerberosAuth.__init__)
session.auth = HTTPKerberosAuth(**kerb_args)
encryption_available = hasattr(session.auth, 'winrm_encryption_available') and session.auth.winrm_encryption_available
elif self.auth_method in ['certificate', 'ssl']:
if self.auth_method == 'ssl' and not self.cert_pem and not self.cert_key_pem:
Expand All @@ -257,15 +252,12 @@ def build_session(self):
elif self.auth_method == 'ntlm':
if not HAVE_NTLM:
raise WinRMError("requested auth method is ntlm, but requests_ntlm is not installed")
man_args = dict(

session.auth = HttpNtlmAuth(
username=self.username,
password=self.password
password=self.password,
send_cbt=self.send_cbt,
)
opt_args = dict(
send_cbt=self.send_cbt
)
ntlm_args = self._get_args(man_args, opt_args, HttpNtlmAuth.__init__)
session.auth = HttpNtlmAuth(**ntlm_args)
# check if requests_ntlm has the session_security attribute available for encryption
encryption_available = hasattr(session.auth, 'session_security')
# TODO: ssl is not exactly right here- should really be client_cert
Expand All @@ -275,17 +267,13 @@ def build_session(self):
if not HAVE_CREDSSP:
raise WinRMError("requests auth method is credssp, but requests-credssp is not installed")

man_args = dict(
session.auth = HttpCredSSPAuth(
username=self.username,
password=self.password
)
opt_args = dict(
password=self.password,
disable_tlsv1_2=self.credssp_disable_tlsv1_2,
auth_mechanism=self.credssp_auth_mechanism,
minimum_version=self.credssp_minimum_version
)
credssp_args = self._get_args(man_args, opt_args, HttpCredSSPAuth.__init__)
session.auth = HttpCredSSPAuth(**credssp_args)
encryption_available = True
else:
raise WinRMError("unsupported auth method: %s" % self.auth_method)
Expand Down Expand Up @@ -355,24 +343,3 @@ def _get_message_response_text(self, response):
else:
response_text = response.content
return response_text

def _get_args(self, mandatory_args, optional_args, function):
argspec = set(inspect.getargspec(function).args)
function_args = dict()
for name, value in mandatory_args.items():
if name in argspec:
function_args[name] = value
else:
raise Exception("Function %s does not contain mandatory arg "
"%s, check installed version with pip list"
% (str(function), name))

for name, value in optional_args.items():
if name in argspec:
function_args[name] = value
else:
warnings.warn("Function %s does not contain optional arg %s, "
"check installed version with pip list"
% (str(function), name))

return function_args

0 comments on commit de7ac17

Please sign in to comment.