@@ -3144,4 +3144,190 @@ void describe('Auth construct', () => {
31443144 UserPoolName : Match . absent ( ) ,
31453145 } ) ;
31463146 } ) ;
3147+
3148+ void describe ( 'passwordless authentication' , ( ) => {
3149+ void it ( 'configures email OTP when otpLogin is enabled' , ( ) => {
3150+ const app = new App ( ) ;
3151+ const stack = new Stack ( app ) ;
3152+ new AmplifyAuth ( stack , 'test' , {
3153+ loginWith : {
3154+ email : {
3155+ otpLogin : true ,
3156+ } ,
3157+ } ,
3158+ } ) ;
3159+ const template = Template . fromStack ( stack ) ;
3160+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
3161+ Policies : {
3162+ SignInPolicy : {
3163+ AllowedFirstAuthFactors : [ 'PASSWORD' , 'EMAIL_OTP' ] ,
3164+ } ,
3165+ } ,
3166+ } ) ;
3167+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolClient' , {
3168+ ExplicitAuthFlows : Match . arrayWith ( [ 'ALLOW_USER_AUTH' ] ) ,
3169+ } ) ;
3170+ } ) ;
3171+
3172+ void it ( 'configures SMS OTP when otpLogin is enabled' , ( ) => {
3173+ const app = new App ( ) ;
3174+ const stack = new Stack ( app ) ;
3175+ new AmplifyAuth ( stack , 'test' , {
3176+ loginWith : {
3177+ phone : {
3178+ otpLogin : true ,
3179+ } ,
3180+ } ,
3181+ } ) ;
3182+ const template = Template . fromStack ( stack ) ;
3183+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
3184+ Policies : {
3185+ SignInPolicy : {
3186+ AllowedFirstAuthFactors : [ 'PASSWORD' , 'SMS_OTP' ] ,
3187+ } ,
3188+ } ,
3189+ } ) ;
3190+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolClient' , {
3191+ ExplicitAuthFlows : Match . arrayWith ( [ 'ALLOW_USER_AUTH' ] ) ,
3192+ } ) ;
3193+ } ) ;
3194+
3195+ void it ( 'configures WebAuthn with default settings' , ( ) => {
3196+ const app = new App ( ) ;
3197+ const stack = new Stack ( app ) ;
3198+ stack . node . setContext ( 'amplify-backend-type' , 'sandbox' ) ;
3199+ new AmplifyAuth ( stack , 'test' , {
3200+ loginWith : {
3201+ email : true ,
3202+ webAuthn : true ,
3203+ } ,
3204+ } ) ;
3205+ const template = Template . fromStack ( stack ) ;
3206+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
3207+ Policies : {
3208+ SignInPolicy : {
3209+ AllowedFirstAuthFactors : [ 'PASSWORD' , 'WEB_AUTHN' ] ,
3210+ } ,
3211+ } ,
3212+ WebAuthnRelyingPartyID : 'localhost' ,
3213+ WebAuthnUserVerification : 'preferred' ,
3214+ } ) ;
3215+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolClient' , {
3216+ ExplicitAuthFlows : Match . arrayWith ( [ 'ALLOW_USER_AUTH' ] ) ,
3217+ } ) ;
3218+ } ) ;
3219+
3220+ void it ( 'configures WebAuthn with custom settings' , ( ) => {
3221+ const app = new App ( ) ;
3222+ const stack = new Stack ( app ) ;
3223+ new AmplifyAuth ( stack , 'test' , {
3224+ loginWith : {
3225+ email : true ,
3226+ webAuthn : {
3227+ relyingPartyId : 'example.com' ,
3228+ userVerification : 'required' ,
3229+ } ,
3230+ } ,
3231+ } ) ;
3232+ const template = Template . fromStack ( stack ) ;
3233+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
3234+ Policies : {
3235+ SignInPolicy : {
3236+ AllowedFirstAuthFactors : [ 'PASSWORD' , 'WEB_AUTHN' ] ,
3237+ } ,
3238+ } ,
3239+ WebAuthnRelyingPartyID : 'example.com' ,
3240+ WebAuthnUserVerification : 'required' ,
3241+ } ) ;
3242+ } ) ;
3243+
3244+ void it ( 'configures all passwordless factors together' , ( ) => {
3245+ const app = new App ( ) ;
3246+ const stack = new Stack ( app ) ;
3247+ new AmplifyAuth ( stack , 'test' , {
3248+ loginWith : {
3249+ email : {
3250+ otpLogin : true ,
3251+ } ,
3252+ phone : {
3253+ otpLogin : true ,
3254+ } ,
3255+ webAuthn : {
3256+ relyingPartyId : 'example.com' ,
3257+ } ,
3258+ } ,
3259+ } ) ;
3260+ const template = Template . fromStack ( stack ) ;
3261+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
3262+ Policies : {
3263+ SignInPolicy : {
3264+ AllowedFirstAuthFactors : [
3265+ 'PASSWORD' ,
3266+ 'EMAIL_OTP' ,
3267+ 'SMS_OTP' ,
3268+ 'WEB_AUTHN' ,
3269+ ] ,
3270+ } ,
3271+ } ,
3272+ WebAuthnRelyingPartyID : 'example.com' ,
3273+ WebAuthnUserVerification : 'preferred' ,
3274+ } ) ;
3275+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolClient' , {
3276+ ExplicitAuthFlows : Match . arrayWith ( [ 'ALLOW_USER_AUTH' ] ) ,
3277+ } ) ;
3278+ } ) ;
3279+
3280+ void it ( 'resolves AUTO to localhost in sandbox mode' , ( ) => {
3281+ const app = new App ( ) ;
3282+ const stack = new Stack ( app ) ;
3283+ stack . node . setContext ( 'amplify-backend-type' , 'sandbox' ) ;
3284+ new AmplifyAuth ( stack , 'test' , {
3285+ loginWith : {
3286+ email : true ,
3287+ webAuthn : true ,
3288+ } ,
3289+ } ) ;
3290+ const template = Template . fromStack ( stack ) ;
3291+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
3292+ WebAuthnRelyingPartyID : 'localhost' ,
3293+ } ) ;
3294+ } ) ;
3295+
3296+ void it ( 'resolves AUTO to Amplify domain in branch mode' , ( ) => {
3297+ const app = new App ( ) ;
3298+ const stack = new Stack ( app ) ;
3299+ stack . node . setContext ( 'amplify-backend-type' , 'branch' ) ;
3300+ stack . node . setContext ( 'amplify-backend-namespace' , 'testProjectName' ) ;
3301+ stack . node . setContext ( 'amplify-backend-name' , 'main' ) ;
3302+ new AmplifyAuth ( stack , 'test' , {
3303+ loginWith : {
3304+ email : true ,
3305+ webAuthn : true ,
3306+ } ,
3307+ } ) ;
3308+ const template = Template . fromStack ( stack ) ;
3309+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
3310+ WebAuthnRelyingPartyID : 'main.testProjectName.amplifyapp.com' ,
3311+ } ) ;
3312+ } ) ;
3313+
3314+ void it ( 'does not configure passwordless when not enabled' , ( ) => {
3315+ const app = new App ( ) ;
3316+ const stack = new Stack ( app ) ;
3317+ new AmplifyAuth ( stack , 'test' , {
3318+ loginWith : {
3319+ email : true ,
3320+ } ,
3321+ } ) ;
3322+ const template = Template . fromStack ( stack ) ;
3323+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
3324+ Policies : {
3325+ PasswordPolicy : Match . objectLike ( { } ) ,
3326+ SignInPolicy : Match . absent ( ) ,
3327+ } ,
3328+ WebAuthnRelyingPartyID : Match . absent ( ) ,
3329+ WebAuthnUserVerification : Match . absent ( ) ,
3330+ } ) ;
3331+ } ) ;
3332+ } ) ;
31473333} ) ;
0 commit comments