forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(apigateway): authorizer is not attached to RestApi across projects (
aws#7596) When an Authorizer is defined in one node project, imported into another where it is wired up with a RestApi, synthesis throws the error 'Authorizer must be attached to a RestApi'. The root cause of this error is the `instanceof` check. If a user has their project set up in a way that more than one instance of the `@aws-cdk/aws-apigateway` module is present in their `node_modules/` folder, even if they are of the exact same version, type checking is bound to fail. Switching instead to a symbol property based comparison, so that type information survives across installations of the module. fixes aws#7377
- Loading branch information
Niranjan Jayakar
authored
Apr 24, 2020
1 parent
861ecdd
commit 1423c53
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Stack } from '@aws-cdk/core'; | ||
import { Test } from 'nodeunit'; | ||
import { Authorizer, RestApi } from '../lib'; | ||
|
||
export = { | ||
'isAuthorizer correctly detects an instance of type Authorizer'(test: Test) { | ||
class MyAuthorizer extends Authorizer { | ||
public readonly authorizerId = 'test-authorizer-id'; | ||
public _attachToApi(_: RestApi): void { | ||
// do nothing | ||
} | ||
} | ||
const stack = new Stack(); | ||
const authorizer = new MyAuthorizer(stack, 'authorizer'); | ||
|
||
test.ok(Authorizer.isAuthorizer(authorizer), 'type Authorizer expected but is not'); | ||
test.ok(!Authorizer.isAuthorizer(stack), 'type Authorizer found, when not expected'); | ||
|
||
test.done(); | ||
}, | ||
}; |