Repository navigation
Fix build frontend codemirror lib error - #36
Merged
maximthomas merged 2 commits intoJun 27, 2022
Merged
maximthomas merged 2 commits into
maximthomas merged 2 commits into
Conversation
maximthomas
added a commit
to maximthomas/OpenIG
that referenced
this pull request
Jul 2, 2024
This was referenced Sep 18, 2026
vharseko
added a commit
to vharseko/OpenIG
that referenced
this pull request
Oct 22, 2026
…t phase grunt-contrib-qunit 1.3 / PhantomJS could no longer load the application, so the "qunit" task had been commented out of the build since 2019 and the JavaScript tests gave no signal. - grunt-contrib-qunit 10 (Puppeteer) with QUnit 2.26 from npm instead of the qunit 1.15 Maven artifact; Chrome runs with --allow-file-access-from-files as the app fetches translations and templates through XHR from file:// - new "grunt test" task bound to the Maven test phase: "mvn verify" fails on a failing JS test, -DskipTests skips the suite - harness: register the EVENT_APP_INITIALIZED listener before starting the app and load the suites only afterwards (their dependencies resolve through the require.config of main.js); start the app from the unbundled target/compose/main.js, as the optimised bundle re-executes jQuery and the other libraries the test page has already loaded - tests migrated to the QUnit 2 API; PhantomJS Function.prototype.bind polyfill removed - tests: assert.throws validates the TransformServiceException type instead of an undefined "expected" (the constructor was called without new); the unknown filter type test now expects "unknownFilterType" - structure.less: CodeMirror stylesheet path follows the libs/codemirror5-4.10.0 location main.js was switched to in OpenIdentityPlatform#36 Fixes OpenIdentityPlatform#175
vharseko
added a commit
that referenced
this pull request
Oct 22, 2026
…ven test phase (#179) Fixes #175. The `qunit` task had been commented out of the `build` task since 2019 (`f270c42a`), and `grunt qunit` itself timed out: grunt-contrib-qunit 1.3 / PhantomJS cannot load the ES2015 app any more. The four suites in `src/test/js/tests` (39 tests) gave no signal. ### Runner - `grunt-contrib-qunit` 1.3.0 → 10.2.0 (headless Chrome via Puppeteer; Chrome is downloaded during `npm install`), QUnit 2.26 from npm instead of the `qunit:1.15.0` Maven artifact (`copy-dependencies-qunit` execution, the two dependencies and the root pom's two `qunit` download items removed). Puppeteer is pinned to 24.43.1 so that every fresh install tests against the same Chrome (openig-ui has no lockfile; the plugin itself asks for `^24.0.0`). - Chrome runs with `--allow-file-access-from-files`: the test page is opened from `file://` and the app fetches translations and templates through XHR, which Chrome blocks for local files by default (PhantomJS did not). `puppeteer.args` replaces the arguments the plugin would build itself, so they are rebuilt next to it: `CHROMIUM_FLAGS` if set, else `--no-sandbox` when `CI` is set. Building as root (e.g. in a container) therefore needs `CI=true` or `CHROMIUM_FLAGS=--no-sandbox`, as with the plugin alone. - New `grunt test` task (`copy:qunit` + `qunit`), bound to the Maven **`test`** phase as a separate execution rather than put back into `build`: `mvn verify` fails on a failing JS test, and `-DskipTests` skips the suite through frontend-maven-plugin's built-in `skipTests` parameter (same layout as OpenAM's `npm-test` execution, OpenIdentityPlatform/OpenAM#902). The plugin never reads `maven.test.skip`, so a `maven-test-skip` profile, active on `-Dmaven.test.skip=true`, skips that execution as well; `<skip>` on the execution itself would have replaced `${skip.grunt}` for it. ### Harness (`config.js` / `run.js`) Two problems only showed up once Chrome actually ran the page: 1. `config.js` required `main` and `../test/run` together. The paths the test suites' dependencies resolve through (`i18next`, `backbone`, …) are set by the `require.config` inside `main.js`; after `grunt build` that is the uglified bundle, which loads slower than the tiny `run.js`, so the dependencies were resolved before the config existed (`Script error for "i18next"`). Historically `qunit` ran in `build-dev` *before* `requirejs`, so the race was won by luck. Now `run.js` registers the `EVENT_APP_INITIALIZED` listener before `main` is required and loads the suites inside that listener. 2. The optimised bundle carries its own copy of jQuery, lodash, bootstrap, …; the test page has already loaded jQuery as a module (needed by `MockServer`/`EventManager`), so executing the bundle created a second jQuery instance — `bootstrap` (shim) attached `$.fn.modal` to the new global while the AMD `bootstrap-dialog` got the old one (`Cannot read properties of undefined (reading 'Constructor')`). The test config therefore starts the app from the unbundled `target/compose/main.js` (`paths.main`); everything else is still served from `target/www`. ### Tests - Migrated to the QUnit 2 API: `module()` → `QUnit.module()`, `QUnit.asyncTest` + `QUnit.start()` → `QUnit.test` (all callbacks under test are synchronous). PhantomJS `Function.prototype.bind` polyfill removed. - `assert.throws(…, transformService.TransformServiceException("invalidModel"), …)` called the constructor without `new`, so `expected` was `undefined` and the assertions only checked that *something* was thrown. They now use a validator that checks `name` and `errorType`; this exposed that the "unknown filter type" test expected `invalidModel` while `transformFilter` throws `unknownFilterType`. - The "no 'name'" and "no 'baseURI'" fixtures each left *both* attributes empty, and `RouteModel.validate()` stops at the first missing one, so neither test could fail if the check it names was removed. Each fixture now leaves out only the attribute under test. - New `StylesheetTests`: every `@import` of the built `css/structure.css` must load. Less keeps a CSS `@import` as it is and a stylesheet that fails to load does not fail the page, which is how the CodeMirror path below stayed broken unnoticed. ### Also - `structure.less` still imported `../libs/CodeMirror-4.10.0/lib/codemirror.css`; #36 moved the CodeMirror location to `libs/codemirror5-4.10.0` in `main.js` only, so the stylesheet has been a 404 in the built UI since then (CodeMirror is used for the route JSON view). Path fixed; `StylesheetTests` now covers it. ### Verification - `mvn -pl openig-ui -am verify`: `grunt-test` → `40 tests completed, 0 failed`, BUILD SUCCESS. - `-DskipTests` and `-Dmaven.test.skip=true`: `grunt-test` → `Skipping execution.`; `-Dskip.grunt=true` still skips both `grunt` and `grunt-test`. - Negative checks against the built copies (each → `1 failed`, grunt exit 6): - a flipped expectation in `DataFilterTests`; - `transformError("invalidModel")` in the unknown filter type test (`Actual: TransformServiceException: UnknownTypeOfFilter`); - the `name` branch, then the `baseURI` branch, removed from `RouteModel.validate()` → the matching "no 'name'" / "no 'baseURI'" test fails; - the old `CodeMirror-4.10.0` path in `structure.css` → `css/../libs/CodeMirror-4.10.0/lib/codemirror.css is loaded` fails. - Chrome arguments: none → `--allow-file-access-from-files`; `CI=true` → `+ --no-sandbox`; `CHROMIUM_FLAGS="--no-sandbox --disable-gpu"` → `+ --no-sandbox --disable-gpu` (suite green); `CHROMIUM_FLAGS` wins over `CI`, as in the plugin. - `grunt eslint`: 0 errors; the 5 warnings are pre-existing in `src/main/js`. - Remaining console noise in the test run is expected: `file:///api/info` (`Footer` → `ServerInfoService.getInfo()` with no backend, handled by its `.fail`) and the resulting "Unknown error" message from the commons REST error handler.
vharseko
added a commit
that referenced
this pull request
Oct 23, 2026
Closes code scanning alerts #36–#39 (`java/dereferenced-value-may-be-null`, `ServerEndPoint`), #34 (`java/input-resource-leak`, `SeparatedValuesFile`) and, in a follow-up commit, #23 / #24 (`java/missing-override-annotation`, the two `onMessage` handlers in `ServerEndPoint`). ### `ServerEndPoint` — a real bug behind the warnings `echoTextMessage` / `echoBinaryMessage` wait up to ~5 s for `session_upstream` and then dereference it without a check, relying on the `NullPointerException` to reach the `catch (Throwable)` that closes the client. Writing a test for that path showed the close never happens: `jakarta.websocket.CloseReason` throws `IllegalArgumentException` for reason phrases longer than 123 UTF-8 bytes (checked in `jakarta.websocket-api-2.0.0`), and the helpful NPE message of Java 14+ (`Cannot invoke "jakarta.websocket.Session.getBasicRemote()" because "this.session_upstream" is null`) is longer than that. `new CloseReason(...)` is evaluated as the argument of `close()`, the exception is swallowed by the inner `catch (Throwable e1) {}`, and **the client connection is left open** with the message silently dropped. The same applies to any exception with a long message in all seven `new CloseReason(..., "…: " + e)` sites in the class. This holds wherever `CloseReason` enforces the limit: the Eclipse `jakarta.websocket-api` (the unit-test classpath), Jetty 11+, Tyrus. Tomcat's own `CloseReason` has no length check and `WsSession` truncates the phrase itself, so on the `openig-docker` image (`tomcat:11-jre25`) the client was already closed and only the reason phrase is affected — except for a phrase over 123 bytes with supplementary characters that is short in UTF-16 units, where `WsSession.appendCloseReasonWithTruncation` throws `StringIndexOutOfBoundsException` and no close frame goes out. Changes: - `upstream()`: the wait loop moved into a method that reads the volatile field once per iteration and fails with `IOException("upstream not connected")` when the upstream is still missing/closed. - `closeReason(code, phrase)`: a phrase over the 123-byte limit is cut to 120 bytes and ends with `…` (U+2026), the marker Tomcat's `WsSession` puts on its own cut, so a truncated reason reads the same on every container. The cut never splits a multi-byte character or a surrogate pair. Every `CloseReason` in the class is now built through it. - `closeUpstream(reason)` / `closeAbnormally(client, phrase)`: null-safe close and reset of the upstream, shared by both `@OnMessage` handlers, `@OnClose` and `@OnError`. The upstream-side `MessageHandler`s still close their own `onOpen` session parameter directly: it is never null, and the field is assigned only after `connectToServer()` returns, while the handlers are registered in `onOpen`. - `@OnMessage` handlers call `authorize()` before waiting for the upstream: a revoked client is closed with `access revoked`, as before, and no longer waits ~5 s for a missing upstream first. - `@OnError` closes the upstream before the client. On Tomcat `close()` runs `@OnClose` on the calling thread, so `end()` used to close the upstream with `NORMAL_CLOSURE` first and the `client error: …` reason never reached it. Now the upstream gets `CLOSED_ABNORMALLY` (sent by Tomcat as 1002), and its `onClose` closes the client with the same reason. - `session_upstream` is `volatile` (written in `@OnOpen`, read from `@OnMessage` on other threads). Tests (`ServerEndPointTest`, new): - text and binary message without an upstream → client closed with `CLOSED_ABNORMALLY` / `"upstream not connected"`. Before the fix both failed with `Wanted but not invoked: session.close(...)` — zero interactions with the client session. - `shouldCloseStaleUpstreamWhenItIsNotOpen`: an upstream that is set but no longer open → client closed with `"upstream not connected"`, the stale session closed and the field cleared. - `shouldTruncateLongUpstreamErrorWhenClosingClient`: the upstream fails with a 200-char `IOException` → the client close phrase is cut to 123 bytes ending in `…`, and the same `CloseReason` closes the upstream (pins the `closeAbnormally()` → `closeReason()` routing; no wait). - `shouldCloseRevokedClientWithoutWaitingForUpstreamOnTextMessage` / `…OnBinaryMessage`: `authorize()` returns 403 and there is no upstream → client closed with exactly `"client message error: access revoked"` (no wait). - `shouldCloseUpstreamWithClientErrorOnError`: `client.close()` runs `end()` as Tomcat does → the upstream is closed once, with `CLOSED_ABNORMALLY` / `"client error: java.io.IOException: broken pipe"`. - `shouldTruncateCloseReasonPhraseToProtocolLimit`: ASCII 123 untouched, 500 → 120 + `…`; Cyrillic 200 → 60 + `…` (123 bytes); `"x"` + U+1F600 ×100 → `"x"` + U+1F600 ×29 + `…` and `"a"` ×119 + U+1F600 ×5 → `"a"` ×119 + `…` (no lone high surrogate at the cut); a lone `\uD83D` and `""` → `""`; short phrases untouched. The three tests that go through the wait (no upstream ×2, stale upstream) each take the real ~5 s (about +18 s on the `openig-core` run); I preferred that over adding a test-only hook to shorten the timeout in production code. ### `ServerEndPoint` — #23 / #24 `@Override` added to `onMessage` of the two anonymous `MessageHandler.Whole` classes (second commit, `1a122ed1`). Folded in here rather than into #180 to keep the file in a single open PR. ### `SeparatedValuesFile` (#34) `SeparatedValuesReader` now `implements Closeable` (it already had `close()`), and `getRecord()` opens it in try-with-resources instead of `try/finally`, with the underlying `FileInputStream` as a resource of its own so that it is closed even if the `InputStreamReader` constructor throws. Behavior-preserving; covered by `SeparatedValuesFileTest` (new), which reads records from a real CSV file. `FileAttributesFilterTest` mocks `SeparatedValuesFile` and does not run this code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.