Module: StandardSingpass::Myinfo::MockModeGuard

Extended by:
T::Sig
Defined in:
lib/standard_singpass/myinfo/mock_mode_guard.rb

Overview

Boot-time guard against running with config.mock_mode enabled where it must never be.

Mock mode short-circuits the FAPI 2.0 dance and serves data from static fixture personas (TestPersonas). That is exactly right for development, CI, and staging rehearsals, and catastrophic in production: real users would submit fabricated identity and income data, and it would be indistinguishable downstream from verified Myinfo data. A mis-set environment variable on one deploy is all it takes, and nothing about the running app looks wrong afterwards — which is why this is a boot-time check rather than a runtime warning.

Three outcomes, deliberately:

production deploy       → raise. The app refuses to boot.
production-*like* deploy → log + report, boot anyway.
anything else           → silent.

The middle tier exists because staging and preview deploys routinely run RAILS_ENV=production while being entirely legitimate places to enable mock mode. Failing those closed would make the guard unusable, and staying silent would hide a genuinely mis-set variable, so they get a loud-but-non-fatal signal instead.

"Production deploy" is decided by config.production_env_detector when set, falling back to Rails.env.production?. The gem cannot know about a host's own environment discriminator (APP_ENVIRONMENT and friends), and deliberately does not read ENV itself — the callable is the seam. This mirrors StandardId's production_env_detector.

Wired automatically from the engine's after_initialize, so a host gets the guard by configuring mock_mode at all. There is no opt-out: a guard you can forget to invoke is a guard that isn't there.

Class Method Summary collapse

Class Method Details

.check!Object



42
43
44
45
46
47
48
49
50
# File 'lib/standard_singpass/myinfo/mock_mode_guard.rb', line 42

def self.check!
  return unless StandardSingpass::Myinfo.configuration.mock_mode

  if production_deploy?
    raise ConfigurationError, production_message
  elsif rails_production?
    report_production_like
  end
end

.production_deploy?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
# File 'lib/standard_singpass/myinfo/mock_mode_guard.rb', line 57

def self.production_deploy?
  detector = StandardSingpass::Myinfo.configuration.production_env_detector
  return !!detector.call if detector

  rails_production?
end