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

Fix proxy type #18166

Merged
merged 7 commits into from
Mar 20, 2024
Merged

Fix proxy type #18166

merged 7 commits into from
Mar 20, 2024

Conversation

condorcorde
Copy link
Contributor

[PowerShell] Fix proxy type (@wing328)

The file configuration.mustache in modules/openapi-generator/src/main/resources/powershell/configuration.mustache contains the following check in the function Set-{{{apiNamePrefix}}}Configuration

If ($Proxy.GetType().FullName -ne "System.Net.SystemWebProxy" -and $Proxy.GetType().FullName -ne "System.Net.WebRequest+WebProxyWrapperOpaque") {
    throw "Incorrect Proxy type '$($Proxy.GetType().FullName)'. Must be System.Net.SystemWebProxy or System.Net.WebRequest+WebProxyWrapperOpaque."
}

The check fails in multiple environments, either because the type checked is unknown, or because the class returned by GetSystemWebProxy() is different from what is expected.

CommandWindows PS 5Windows PS7MacOS PS 7
$PSVersionTable Name Value ---- ----- PSVersion 5.1.19041.4046 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.4046 [...]Name Value ---- ----- PSVersion 7.4.1 PSEdition Core GitCommitId 7.4.1 OS Microsoft Windows 10.0.19045 Platform Win32NT [...]Name Value ---- ----- PSVersion 7.4.1 PSEdition Core GitCommitId 7.4.1 OS Darwin 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:31 PST 2024; root:xnu-1006… Platform Unix [...]
[System.Net.SystemWebProxy]$aUnable to find type [System.Net.SystemWebProxy]. At line:1 char:2 + [System.Net.SystemWebProxy]$a + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.SystemWebProxy:TypeName) [], RuntimeException + FullyQualifiedErrorId : TypeNotFoundInvalidOperation: Unable to find type [System.Net.SystemWebProxy].InvalidOperation: Unable to find type [System.Net.SystemWebProxy].
([System.Net.WebRequest]:: GetSystemWebProxy()).GetType()IsPublic IsSerial Name BaseType -------- -------- ---- -------- False False WebProxyWrapperOpaque System.Object IsPublic IsSerial Name BaseType -------- -------- ---- -------- False False HttpWindowsProxy System.Object IsPublic IsSerial Name BaseType -------- -------- ---- -------- False False MacProxy System.Object

Since all returned types implement (and by the available doc, shall implement) the interface IWebProxy, I propose to replace the above test with

If ('System.Net.IWebProxy' -notin $Proxy.GetType().ImplementedInterfaces.FullName) {
    throw "Incorrect Proxy type '$($Proxy.GetType().FullName)'. Must implement System.Net.IWebProxy interface."
}

The change does not guarantee that the configured proxy will work on all systems (e.g. on Linux the default class is HttpNoProxy, and on MacOS proxy credentials are likely not yet implemented). Yet, when using the command

Set-PSConfiguration -Proxy ([system.net.webproxy]::new('http://127.0.0.1:8080')) -SkipCertificateCheck

the request and response are intercepted as requested in the proxy, and can be used for debugging.

The test can be made by using e.g. Burp Suite Community Edition, enabling the proxy on 127.0.0.1:8080 and using the line above to configure the PowerShell PetStore client API.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@wing328
Copy link
Member

wing328 commented Mar 20, 2024

PS tests passed via https://ci.appveyor.com/project/WilliamCheng/openapi-generator/builds/49441588

thanks for the PR, let's give it a try

@wing328 wing328 merged commit de081e4 into OpenAPITools:master Mar 20, 2024
14 checks passed
@wing328 wing328 added this to the 7.5.0 milestone Mar 20, 2024
zapodot pushed a commit to zapodot/openapi-generator that referenced this pull request Mar 21, 2024
* Update configuration.mustache

Fix check of proxy type

* Changing sample source files
@condorcorde condorcorde deleted the fix-proxy-type branch April 4, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants