@@ -1316,6 +1316,78 @@ def test_authenticate_with_account_store_org_href_succeeds(self):
13161316 self .assertEqual (claims .get ('org' ), self .org .href )
13171317
13181318
1319+ class TestClientCredentialsGrantAuthenticator (ApiKeyBase ):
1320+
1321+ def setUp (self ):
1322+ super (TestClientCredentialsGrantAuthenticator , self ).setUp ()
1323+
1324+ self .username = self .get_random_name ()
1325+ self .password = 'W00t123!' + self .username
1326+ _ , self .acc = self .create_account (self .app .accounts ,
1327+ username = self .username ,
1328+ password = self .password )
1329+
1330+ self .user_api_key = self .acc .api_keys .create ()
1331+
1332+ org_name = self .get_random_name ()
1333+ org_name_key = org_name [:63 ]
1334+
1335+ self .org = self .client .tenant .organizations .create ({
1336+ 'name' : org_name ,
1337+ 'name_key' : org_name_key ,
1338+ })
1339+ self .client .organization_account_store_mappings .create ({
1340+ 'account_store' : self .dir ,
1341+ 'organization' : self .org ,
1342+ })
1343+ self .client .account_store_mappings .create ({
1344+ 'account_store' : self .org ,
1345+ 'application' : self .app ,
1346+ })
1347+
1348+ def test_authenticate_succeeds (self ):
1349+ authenticator = ClientCredentialsGrantAuthenticator (self .app )
1350+ result = authenticator .authenticate (self .user_api_key .id ,
1351+ self .user_api_key .secret )
1352+
1353+ self .assertTrue (result .access_token )
1354+ self .assertFalse (result .refresh_token .token )
1355+ self .assertTrue (result .stormpath_access_token )
1356+ self .assertEqual (result .token_type , 'Bearer' )
1357+ self .assertEqual (result .expires_in , 3600 )
1358+ self .assertEqual (result .account .href , self .acc .href )
1359+
1360+ def test_authenticate_fails (self ):
1361+ authenticator = ClientCredentialsGrantAuthenticator (self .app )
1362+ result = authenticator .authenticate ('wrong id' , 'wrong secret' )
1363+
1364+ self .assertIsNone (result )
1365+
1366+ def test_authenticate_with_account_store_succeeds (self ):
1367+ authenticator = ClientCredentialsGrantAuthenticator (self .app )
1368+ result = authenticator .authenticate (self .user_api_key .id ,
1369+ self .user_api_key .secret ,
1370+ account_store = self .dir )
1371+
1372+ self .assertTrue (result .access_token )
1373+ self .assertEqual (result .account .href , self .acc .href )
1374+ self .assertTrue ('access_token' in result .access_token .to_json ())
1375+ self .assertTrue (hasattr (result .stormpath_access_token , 'href' ))
1376+ self .assertEqual (result .stormpath_access_token .account .href ,
1377+ self .acc .href )
1378+ self .assertEqual (result .token_type , 'Bearer' )
1379+ self .assertEqual (result .expires_in , 3600 )
1380+ self .assertEqual (result .account .href , self .acc .href )
1381+
1382+ def test_authenticate_with_account_store_fails (self ):
1383+ authenticator = ClientCredentialsGrantAuthenticator (self .app )
1384+ result = authenticator .authenticate ('wrong id' ,
1385+ 'wrong secret' ,
1386+ account_store = self .dir )
1387+
1388+ self .assertIsNone (result )
1389+
1390+
13191391class TestJwtAuthenticator (ApiKeyBase ):
13201392 def setUp (self ):
13211393 super (TestJwtAuthenticator , self ).setUp ()
@@ -1602,3 +1674,29 @@ def test_authenticate_with_invalid_token_fails(self):
16021674 result = authenticator .authenticate ('invalid_token' )
16031675
16041676 self .assertIsNone (result )
1677+
1678+
1679+ class TestTokenRevocation (ApiKeyBase ):
1680+
1681+ def setUp (self ):
1682+ super (TestTokenRevocation , self ).setUp ()
1683+
1684+ self .username = self .get_random_name ()
1685+ self .password = 'W00t123!' + self .username
1686+ _ , self .acc = self .create_account (self .app .accounts ,
1687+ username = self .username ,
1688+ password = self .password )
1689+
1690+ def test_revoke_token_succeeds (self ):
1691+ authenticator = PasswordGrantAuthenticator (self .app )
1692+ result = authenticator .authenticate (self .username , self .password )
1693+
1694+ self .assertTrue (result .access_token )
1695+ self .assertEqual (result .account .href , self .acc .href )
1696+
1697+ acc_tokens = self .acc .access_tokens
1698+ self .assertEqual (len (acc_tokens .items ), 1 )
1699+
1700+ acc_tokens .items [0 ].delete ()
1701+ acc_tokens .refresh ()
1702+ self .assertEqual (len (acc_tokens .items ), 0 )
0 commit comments