-
Notifications
You must be signed in to change notification settings - Fork 24
feat: Enables CORS and JWT configuration for WebApplications in CspApplication tag #973
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
base: main
Are you sure you want to change the base?
Changes from all commits
746fa55
e88d6f1
2897899
eb36e6b
f38df20
eb90948
e23691b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /// This class validates that CORS headers and allowed origins are configured correctly, | ||
| /// and that JWT authentication is properly set up in the <b><WebApplication></b> configuration section. | ||
| Class Test.PM.Integration.ResourceProcessor.WebApplication Extends Test.PM.Integration.Base | ||
| { | ||
|
|
||
| Parameter CommonPathPrefix As STRING = "cors-rest-apps"; | ||
|
|
||
| Parameter WebAppName As STRING = "/testcors"; | ||
|
|
||
| /// Test.PM.Integration.Uninstall | ||
| Method TestCORSEnabledWebAppViaModule() | ||
| { | ||
| #define NormalizeDirectory(%path) ##class(%File).NormalizeDirectory(%path) | ||
| #define UTRoot ^UnitTestRoot | ||
|
|
||
| set testRoot = $$$NormalizeDirectory($get($$$UTRoot)) | ||
| set moduleDir = $$$NormalizeDirectory(##class(%File).GetDirectory(testRoot)_"/_data/"_..#CommonPathPrefix_"/") | ||
| set moduleFile = ##class(%File).NormalizeFilename("module.xml",moduleDir) | ||
| if ##class(%File).DirectoryExists(moduleFile) { | ||
| do $$$AssertStatusOK(1,"module.xml File exist on "_moduleDir) | ||
| } | ||
| set status = ##class(%IPM.Main).Shell("load "_moduleDir) | ||
| do $$$AssertStatusOK(status,"Loaded "_..#CommonPathPrefix_" module successfully from "_moduleDir) | ||
| do ..VerifyCORSConfiguration() | ||
| do ..VerifyJWTConfiguration() | ||
|
|
||
| set status = ##class(%IPM.Main).Shell("uninstall "_..#CommonPathPrefix) | ||
| do $$$AssertStatusOK(status,"uninstalled "_..#CommonPathPrefix_" module successfully.") | ||
| } | ||
|
|
||
| Method VerifyCORSConfiguration() | ||
| { | ||
| new $namespace | ||
| set $namespace = "%SYS" | ||
| set status = ##class(Security.Applications).Get(..#WebAppName, .props) | ||
| do $$$AssertStatusOK(status,"Web applciation "_..#WebAppName_" created scuccessfully") | ||
| if $data(props("CorsAllowlist"),corsAllowlist) { | ||
| do $$$AssertStatusOK(1,"CorsAllowlist values are defined") | ||
| do $$$LogMessage(corsAllowlist) | ||
| } | ||
| if $data(props("CorsCredentialsAllowed"),corsAllow) { | ||
| do $$$AssertStatusOK(1,"CorsCredentialsAllowed values are defined") | ||
| do $$$LogMessage(corsAllow) | ||
| } | ||
| if $data(props("CorsHeadersList"),corsHeadersList) { | ||
| do $$$AssertStatusOK(1,"CorsHeadersList values are defined") | ||
| do $$$LogMessage(corsHeadersList) | ||
| } | ||
| } | ||
|
|
||
| Method VerifyJWTConfiguration() | ||
| { | ||
| new $namespace | ||
| set $namespace = "%SYS" | ||
| set status = ##class(Security.Applications).Get(..#WebAppName, .props) | ||
| do $$$AssertStatusOK(status,"Web applciation "_..#WebAppName_" created scuccessfully") | ||
| do $$$LogMessage("Validating JWT configuration") | ||
| if $data(props("JWTAccessTokenTimeout"),JWTAccessTokenTimeout) { | ||
| do $$$AssertStatusOK(1,"JWTAccessTokenTimeout value is defined") | ||
| do $$$LogMessage(JWTAccessTokenTimeout) | ||
| } | ||
| if $data(props("JWTAuthEnabled"),JWTAuthEnabled) { | ||
| do $$$AssertStatusOK(1,"JWTAuthEnabled value is defined") | ||
| do $$$LogMessage(JWTAuthEnabled) | ||
| } | ||
| if $data(props("JWTRefreshTokenTimeout"),JWTRefreshTokenTimeout) { | ||
| do $$$AssertStatusOK(1,"JWTRefreshTokenTimeout value is defined") | ||
| do $$$LogMessage(JWTRefreshTokenTimeout) | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Export generator="Cache" version="25"> | ||
| <Document name="cors-rest-apps.ZPM"> | ||
| <Module> | ||
| <Name>cors-rest-apps</Name> | ||
| <Version>1.0.0</Version> | ||
| <Description>cors enabling testing on webapplication</Description> | ||
| <Keywords>cors</Keywords> | ||
| <Packaging>module</Packaging> | ||
| <Resource Name="CorsTest.PKG"/> | ||
| <WebApplication | ||
| CookiePath="/testcors" | ||
| CorsAllowlist="https://www.example.com,https://pm.intersystems.com" | ||
| CorsCredentialsAllowed="1" | ||
| JWTAccessTokenTimeout="60" | ||
| JWTAuthEnabled="1" | ||
| JWTRefreshTokenTimeout="900" | ||
| CorsHeadersList="Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Allow-Credentials, Access-Control-Max-Age, Access-Control-Expose-Headers, Access-Control-Request-Method, Access-Control-Request-Headers" | ||
| PasswordAuthEnabled="1" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For WebApplication, these properties for auth are all encapsulated as part of AutheEnabled and not separate properties.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @isc-kiyer
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Presumably this refers to how AutheEnabled is a bit string with these properties, e.g. AutheEnabled=32 means PasswordAuthEnabled=1
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @isc-kiyer , @isc-dchui
<WebApplication
Url="/testcors"
CookiePath="/testcors"
AutheEnabled="32"
JWTAuthEnabled="1"
JWTAccessTokenTimeout="60"
JWTRefreshTokenTimeout="900"
CorsCredentialsAllowed="1"
CorsAllowlist="https://www.example.com"
CorsHeadersList="Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers"
PasswordAuthEnabled="1"
UnauthenticatedEnabled="0"
Recurse="1"
UseCookies="2" />
Could you check and suggest. |
||
| Recurse="1" | ||
| UnauthenticatedEnabled="0" | ||
| Url="/testcors" | ||
| UseCookies="2"/> | ||
| <LifecycleClass>%IPM.Lifecycle.Module</LifecycleClass> | ||
| <SourcesRoot>src</SourcesRoot> | ||
| </Module> | ||
| </Document> | ||
| </Export> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Class CorsTest.Rest.Cors Extends %RegisteredObject | ||
| { | ||
|
|
||
| XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ] | ||
| { | ||
| <Routes> | ||
| <Route Url="/" Method="GET" Call="GetInfo" Cors="true"/> | ||
| </Routes> | ||
| } | ||
|
|
||
| ClassMethod GetInfo() As %Status | ||
| { | ||
| write "Hello, World!" | ||
| quit $$$OK | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: missing space between
)and{There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed the space issue