@@ -1652,7 +1652,8 @@ describe('apple signin auth adapter', () => {
16521652
16531653describe ( 'Apple Game Center Auth adapter' , ( ) => {
16541654 const gcenter = require ( '../lib/Adapters/Auth/gcenter' ) ;
1655-
1655+ const fs = require ( 'fs' ) ;
1656+ const testCert = fs . readFileSync ( __dirname + '/support/cert/game_center.pem' ) ;
16561657 it ( 'validateAuthData should validate' , async ( ) => {
16571658 // real token is used
16581659 const authData = {
@@ -1664,68 +1665,51 @@ describe('Apple Game Center Auth adapter', () => {
16641665 salt : 'DzqqrQ==' ,
16651666 bundleId : 'cloud.xtralife.gamecenterauth' ,
16661667 } ;
1667-
1668- try {
1669- await gcenter . validateAuthData ( authData ) ;
1670- } catch ( e ) {
1671- fail ( ) ;
1672- }
1668+ gcenter . cache [ 'https://static.gc.apple.com/public-key/gc-prod-4.cer' ] = testCert ;
1669+ await gcenter . validateAuthData ( authData ) ;
16731670 } ) ;
16741671
16751672 it ( 'validateAuthData invalid signature id' , async ( ) => {
16761673 const authData = {
16771674 id : 'G:1965586982' ,
1678- publicKeyUrl : 'https://static.gc.apple.com/public-key/gc-prod-4.cer' ,
1679- timestamp : 1565257031287 ,
1680- signature : '1234' ,
1681- salt : 'DzqqrQ==' ,
1682- bundleId : 'cloud.xtralife.gamecenterauth' ,
1683- } ;
1684-
1685- try {
1686- await gcenter . validateAuthData ( authData ) ;
1687- fail ( ) ;
1688- } catch ( e ) {
1689- expect ( e . message ) . toBe ( 'Apple Game Center - invalid signature' ) ;
1690- }
1691- } ) ;
1692-
1693- it ( 'validateAuthData invalid public key url' , async ( ) => {
1694- const authData = {
1695- id : 'G:1965586982' ,
1696- publicKeyUrl : 'invalid.com' ,
1675+ publicKeyUrl : 'https://static.gc.apple.com/public-key/gc-prod-6.cer' ,
16971676 timestamp : 1565257031287 ,
16981677 signature : '1234' ,
16991678 salt : 'DzqqrQ==' ,
1700- bundleId : 'cloud.xtralife.gamecenterauth ' ,
1679+ bundleId : 'com.example.com ' ,
17011680 } ;
1702-
1703- try {
1704- await gcenter . validateAuthData ( authData ) ;
1705- fail ( ) ;
1706- } catch ( e ) {
1707- expect ( e . message ) . toBe ( 'Apple Game Center - invalid publicKeyUrl: invalid.com' ) ;
1708- }
1681+ await expectAsync ( gcenter . validateAuthData ( authData ) ) . toBeRejectedWith (
1682+ new Parse . Error ( Parse . Error . SCRIPT_FAILED , 'Apple Game Center - invalid signature' )
1683+ ) ;
17091684 } ) ;
17101685
17111686 it ( 'validateAuthData invalid public key http url' , async ( ) => {
1712- const authData = {
1713- id : 'G:1965586982' ,
1714- publicKeyUrl : 'http://static.gc.apple.com/public-key/gc-prod-4.cer' ,
1715- timestamp : 1565257031287 ,
1716- signature : '1234' ,
1717- salt : 'DzqqrQ==' ,
1718- bundleId : 'cloud.xtralife.gamecenterauth' ,
1719- } ;
1720-
1721- try {
1722- await gcenter . validateAuthData ( authData ) ;
1723- fail ( ) ;
1724- } catch ( e ) {
1725- expect ( e . message ) . toBe (
1726- 'Apple Game Center - invalid publicKeyUrl: http://static.gc.apple.com/public-key/gc-prod-4.cer'
1727- ) ;
1728- }
1687+ const publicKeyUrls = [
1688+ 'example.com' ,
1689+ 'http://static.gc.apple.com/public-key/gc-prod-4.cer' ,
1690+ 'https://developer.apple.com/assets/elements/badges/download-on-the-app-store.svg' ,
1691+ 'https://example.com/ \\.apple.com/public_key.cer' ,
1692+ 'https://example.com/ &.apple.com/public_key.cer' ,
1693+ ] ;
1694+ await Promise . all (
1695+ publicKeyUrls . map ( publicKeyUrl =>
1696+ expectAsync (
1697+ gcenter . validateAuthData ( {
1698+ id : 'G:1965586982' ,
1699+ timestamp : 1565257031287 ,
1700+ publicKeyUrl,
1701+ signature : '1234' ,
1702+ salt : 'DzqqrQ==' ,
1703+ bundleId : 'com.example.com' ,
1704+ } )
1705+ ) . toBeRejectedWith (
1706+ new Parse . Error (
1707+ Parse . Error . SCRIPT_FAILED ,
1708+ `Apple Game Center - invalid publicKeyUrl: ${ publicKeyUrl } `
1709+ )
1710+ )
1711+ )
1712+ ) ;
17291713 } ) ;
17301714} ) ;
17311715
0 commit comments