Skip to content

Commit

Permalink
fix: stable features with ack now throw to indicate a possible breaki…
Browse files Browse the repository at this point in the history
…ng change
  • Loading branch information
panva committed Mar 3, 2020
1 parent e086fc6 commit cf58d35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/helpers/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ class Configuration {

checkRuntimeFeatures() {
if (this.features.mTLS.enabled && !runtimeSupport.KeyObject) {
throw new Error('mTLS can only be enabled on Node.js >= 12.0.0 runtime');
throw new TypeError('mTLS can only be enabled on Node.js >= 12.0.0 runtime');
}
if ((this.formats.AccessToken === 'paseto' || this.formats.ClientCredentials === 'paseto') && !runtimeSupport.EdDSA) {
throw new Error('paseto structured tokens can only be enabled on Node.js >= 12.0.0 runtime');
throw new TypeError('paseto structured tokens can only be enabled on Node.js >= 12.0.0 runtime');
}
}

Expand Down Expand Up @@ -275,7 +275,7 @@ class Configuration {
}

if (alg === 'ES256K' && !this.features.secp256k1.enabled) {
throw new Error('`features.secp256k1` must be enabled before enabling support for ES256K');
throw new TypeError('`features.secp256k1` must be enabled before enabling support for ES256K');
}
});
});
Expand Down Expand Up @@ -372,26 +372,26 @@ class Configuration {
const { features } = this;

if (features.pushedAuthorizationRequests.enabled && !features.requestObjects.requestUri) {
throw new Error('pushedAuthorizationRequests is only available in conjuction with requestObjects.requestUri');
throw new TypeError('pushedAuthorizationRequests is only available in conjuction with requestObjects.requestUri');
}

if (features.jwtIntrospection.enabled && !features.introspection.enabled) {
throw new Error('jwtIntrospection is only available in conjuction with introspection');
throw new TypeError('jwtIntrospection is only available in conjuction with introspection');
}

if (features.jwtUserinfo.enabled && !features.userinfo.enabled) {
throw new Error('jwtUserinfo is only available in conjuction with userinfo');
throw new TypeError('jwtUserinfo is only available in conjuction with userinfo');
}

if (features.registrationManagement.enabled && !features.registration.enabled) {
throw new Error('registrationManagement is only available in conjuction with registration');
throw new TypeError('registrationManagement is only available in conjuction with registration');
}

if (
(features.registration.enabled && features.registration.policies)
&& !features.registration.initialAccessToken
) {
throw new Error('registration policies are only available in conjuction with adapter-backed initial access tokens');
throw new TypeError('registration policies are only available in conjuction with adapter-backed initial access tokens');
}
}

Expand Down Expand Up @@ -507,6 +507,10 @@ class Configuration {
}
ENABLED_DRAFTS.add(flag);
}

if (enabled && !draft && ack !== undefined) {
throw new TypeError(`${flag} feature is now stable, the ack ${ack} is no longer valid. Check the stable feature's configuration for any breaking changes.`);
}
});

/* istanbul ignore if */
Expand All @@ -530,7 +534,7 @@ class Configuration {
attention.info(`You may disable this notice and these potentially breaking updates by acknowledging the current draft version. See ${docs('features')}`);

if (throwDraft) {
throw new Error('An unacknowledged version of a draft feature is included in this oidc-provider version.');
throw new TypeError('An unacknowledged version of a draft feature is included in this oidc-provider version.');
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/configuration/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ describe('Provider configuration', () => {
}).to.throw('Unknown feature configuration: foo');
});

it('checks that a stable feature does not have an ack', () => {
expect(() => {
new Configuration({ // eslint-disable-line no-new
features: {
deviceFlow: {
enabled: true,
ack: 'draft-01',
},
},
});
}).to.throw("deviceFlow feature is now stable, the ack draft-01 is no longer valid. Check the stable feature's configuration for any breaking changes.");
});

it('checks that a feature configuration is not a boolean', () => {
expect(() => {
new Configuration({ // eslint-disable-line no-new
Expand Down

0 comments on commit cf58d35

Please sign in to comment.