Repository navigation
fix(config): reject a plan type outside paygo | token | coding - #459
Merged
Merged
Conversation
validate() checked the protocol enum but never the plan type. A config with type = "payg" parsed, validated and started, and the key-listing form then reported the plan as a subscription: showPlanHint() in ui/js/app.js tests only for "paygo" and renders every other value as share.plan.sub. A pay-as-you-go key was advertised as a subscription, with no error, warning or log line. Reject it at load, in the same shape as the protocol check it sits beside, so the message names the plan and the allowed values. No plan in config/config.example.toml is affected; all 16 use the documented values.
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.
Summary
validate()checks that a plan'sprotocolis one of three values, but never looked attype, which is the same kind of closed set. A config withtype = "payg"parsed, validated and started, and the key-listing form then advertised the plan as a subscription:showPlanHint()inui/js/app.jstests only for"paygo"and renders every other value asshare.plan.sub("Subscription Plan"). A pay-as-you-go key was therefore shown as a subscription, with no error, warning or log line anywhere.This adds the missing match to
validate(), beside the existing protocol check, so a mistypedtypeis rejected at load with a message that names the plan and the allowed values.Changes
src/config.rs:validate()now rejects a plantypeoutsidepaygo | token | coding, in the same shape as the protocol check a few lines below it. The function's doc comment lists the new rule and records why it exists (the frontend only recognises the three values, so anything else is silently rendered as a subscription).src/config.rs: new testvalidate_rejects_illegal_plan_type, which asserts the error names both the rule and the offending plan id.Tests
cargo test— 618 passed, 0 failed (617 before this change)cargo fmt --check— cleancargo clippy --all-targets -- -D warnings— cleanunwrap_err()overOk, i.e.validate()acceptedtype = "payg". It fails on that assertion, not on a missing symbol.Behaviour change
A deployment whose
config.tomlcarries a plan type outside the three documented values will now refuse to start, naming the plan and the allowed values, instead of starting and mislabelling the plan. Nothing in this repository is affected: all 16 plans inconfig/config.example.tomluse the documented values, andcatalog_gatealready asserts that file passesvalidate().I chose the reject-at-load direction because it is this function's existing shape for a closed set (the protocol check above it) and because the alternative — accepting the value and only fixing the label — leaves the config stating something the platform does not mean. If you would rather tolerate unknown values for forward compatibility, say so and I will turn this into a normalisation instead.
Not in this change
Plan.interactive_onlyis declared in the config (with the note "interactive coding tools only, automated batch calls prohibited (compliance)") and is passed through to clients byGET /api/plans, but nothing reads it: no reference inui/js, no enforcement anywhere in the gateway. Either it is a marker meant for human readers, or it is a restriction that was never implemented. I left it alone because which one it is is your call, and it is now tracked as #460, which this pull request deliberately does not close — an issue asking a question should not be closed by a change that only fixes its sibling. It seemed worth naming here too rather than leaving it to be rediscovered.