Skip to content

fix(integration): guard unguarded X(...)[0] indexing in the nwo test harness - #1923

Merged
mbrandenburger merged 1 commit into
hyperledger-labs:mainfrom
mbrandenburger:worktree-issue-1861-unguarded-index
Sep 29, 2026
Merged

mbrandenburger merged 1 commit into
hyperledger-labs:mainfrom
mbrandenburger:worktree-issue-1861-unguarded-index

Conversation

@mbrandenburger

Copy link
Copy Markdown
Member

Summary

  • Guards several nwo test-harness call sites that read the first element of a platform/peer/org lookup, or type-assert a platform, without checking the collection is non-empty or the assertion succeeded. On an unexpected topology these panicked with a generic index-out-of-range or interface-conversion message; they now fail the spec with a descriptive gomega.Expect message.
  • Guarded sites: integration.go's ViewCmd, runtimeconfig/commands.go's InjectAll, nwo/fabric/platform.go's UserByOrg/UsersByOrg/InvokeChaincode/ConnectionProfile, and nwo/monitoring/monitoring/monitoring.go's fscScrapes/fscCryptoDir.
  • Adds Godoc to each guarded function documenting when it fails the test, plus unit tests covering the happy path and each guard panic.

Test plan

  • make checks (lint + go fix) — 0 issues across all modules
  • go test ./nwo/fabric/... ./nwo/monitoring/... -v — all tests pass

Fixes #1918

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Hey @mbrandenburger 👋 thanks for the PR!
I'm your friendly PR Helper Bot 🤖 and I'll be riding shotgun on this one, keeping track of your PR's status to help you get it approved and merged.

This comment updates automatically as you push changes -- think of it as your PR's live scoreboard!
Here's the latest:


PR Checks

✅ DCO Sign-off -- All commits have valid sign-offs. Nice work!


❌ GPG Signature -- Heads up! The following commits don't have a verified GPG signature:

  • 0767b4e fix(integration): guard unguarded X(...)[0] indexing in the nwo test harness

You'll need to sign your commits with GPG (e.g. git commit -S). See the Signing Guide for a step-by-step walkthrough.


✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing!


✅ Issue Link -- Linked to #1918 (assigned to you).


⏳ All checks must pass before this PR can be reviewed. You've got this!

@github-actions github-actions Bot added the status: needs revision The pull request requires changes from the author before it can be reviewed or merged label Sep 28, 2026
@mbrandenburger mbrandenburger added this to the 26Q3 milestone Sep 28, 2026
@mbrandenburger mbrandenburger added status: needs review The pull request is ready for maintainer review and removed status: needs revision The pull request requires changes from the author before it can be reviewed or merged labels Sep 28, 2026
…harness

Several call sites read the first element of a platform/peer/org lookup
without checking that the collection was non-empty, or type-asserted a
platform without checking the assertion. On an unexpected topology (e.g.
a peer org with no peers, or no fabric/fsc platform registered) these
panicked with a generic "index out of range" or interface-conversion
message instead of a clear test failure explaining what was expected.

Guard each site with the gomega.Expect(...).To(gomega.HaveLen(1)) /
ok-checked type-assertion idiom already used in
integration/fabric/configupdate/configupdate.go, so a violated
invariant fails the spec with a descriptive message:

- integration/integration.go: ViewCmd's fsc platform lookup
- integration/fabric/runtimeconfig/commands.go: InjectAll's fabric
  platform lookup
- integration/nwo/fabric/platform.go: UserByOrg, UsersByOrg,
  InvokeChaincode and ConnectionProfile's peer/org lookups
- integration/nwo/monitoring/monitoring/monitoring.go: fscScrapes and
  fscCryptoDir's fsc platform lookup

Document when each guarded function fails the test, and add unit tests
exercising both the happy path and the guard panics in platform.go and
monitoring.go. Tests use only testify/require in their bodies; a
package-level TestMain registers gomega's fail handler to panic
(mirroring integration.go's Ginkgo setup) so the guarded gomega.Expect
calls raise a catchable panic under go test.

Fixes hyperledger-labs#1918

Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
@mergify

mergify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@SaidAltury-ibm
SaidAltury-ibm force-pushed the worktree-issue-1861-unguarded-index branch from 225b994 to 0767b4e Compare September 29, 2026 08:23
@github-actions github-actions Bot added status: needs revision The pull request requires changes from the author before it can be reviewed or merged and removed status: needs review The pull request is ready for maintainer review labels Sep 29, 2026
@mbrandenburger
mbrandenburger merged commit d63e60d into hyperledger-labs:main Sep 29, 2026
45 checks passed
@mbrandenburger
mbrandenburger deleted the worktree-issue-1861-unguarded-index branch September 29, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs revision The pull request requires changes from the author before it can be reviewed or merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic risk audit follow-up: unguarded X(...)[0] pattern in the integration test harness

2 participants