@@ -1715,6 +1715,14 @@ func TestUserForgotPassword(t *testing.T) {
1715
1715
Password :newPassword ,
1716
1716
})
1717
1717
require .NoError (t ,err )
1718
+
1719
+ // We now need to check that the one-time passcode isn't valid.
1720
+ err = anotherClient .ChangePasswordWithOneTimePasscode (ctx , codersdk.ChangePasswordWithOneTimePasscodeRequest {
1721
+ Email :anotherUser .Email ,
1722
+ OneTimePasscode :oneTimePasscode ,
1723
+ Password :"SomeDifferentSecurePassword!" ,
1724
+ })
1725
+ require .Error (t ,err )
1718
1726
})
1719
1727
1720
1728
t .Run ("CannotChangePasswordWithInvalidOneTimePasscode" ,func (t * testing.T ) {
@@ -1754,6 +1762,43 @@ func TestUserForgotPassword(t *testing.T) {
1754
1762
require .Equal (t ,http .StatusBadRequest ,apiErr .StatusCode ())
1755
1763
})
1756
1764
1765
+ t .Run ("CannotChangePasswordWithNoOneTimePasscode" ,func (t * testing.T ) {
1766
+ t .Parallel ()
1767
+
1768
+ notifyEnq := & testutil.FakeNotificationsEnqueuer {}
1769
+
1770
+ client := coderdtest .New (t ,& coderdtest.Options {
1771
+ NotificationsEnqueuer :notifyEnq ,
1772
+ })
1773
+ user := coderdtest .CreateFirstUser (t ,client )
1774
+
1775
+ ctx ,cancel := context .WithTimeout (context .Background (),testutil .WaitLong )
1776
+ defer cancel ()
1777
+
1778
+ anotherClient ,anotherUser := coderdtest .CreateAnotherUser (t ,client ,user .OrganizationID )
1779
+
1780
+ err := anotherClient .RequestOneTimePasscode (ctx , codersdk.RequestOneTimePasscodeRequest {
1781
+ Email :anotherUser .Email ,
1782
+ })
1783
+ require .NoError (t ,err )
1784
+
1785
+ require .Equal (t ,2 ,len (notifyEnq .Sent ))
1786
+
1787
+ notif := notifyEnq .Sent [1 ]
1788
+ verifyOneTimePasscodeNotification (t ,notif ,anotherUser .ID )
1789
+
1790
+ err = anotherClient .ChangePasswordWithOneTimePasscode (ctx , codersdk.ChangePasswordWithOneTimePasscodeRequest {
1791
+ Email :anotherUser .Email ,
1792
+ OneTimePasscode :"" ,
1793
+ Password :"SomeNewSecurePassword!" ,
1794
+ })
1795
+ require .Error (t ,err )
1796
+
1797
+ var apiErr * codersdk.Error
1798
+ require .ErrorAs (t ,err ,& apiErr )
1799
+ require .Equal (t ,http .StatusBadRequest ,apiErr .StatusCode ())
1800
+ })
1801
+
1757
1802
t .Run ("CannotChangePasswordWithWeakPassword" ,func (t * testing.T ) {
1758
1803
t .Parallel ()
1759
1804