@@ -1652,7 +1652,8 @@ describe('apple signin auth adapter', () => {
1652
1652
1653
1653
describe ( 'Apple Game Center Auth adapter' , ( ) => {
1654
1654
const gcenter = require ( '../lib/Adapters/Auth/gcenter' ) ;
1655
-
1655
+ const fs = require ( 'fs' ) ;
1656
+ const testCert = fs . readFileSync ( __dirname + '/support/cert/game_center.pem' ) ;
1656
1657
it ( 'validateAuthData should validate' , async ( ) => {
1657
1658
// real token is used
1658
1659
const authData = {
@@ -1664,68 +1665,51 @@ describe('Apple Game Center Auth adapter', () => {
1664
1665
salt : 'DzqqrQ==' ,
1665
1666
bundleId : 'cloud.xtralife.gamecenterauth' ,
1666
1667
} ;
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 ) ;
1673
1670
} ) ;
1674
1671
1675
1672
it ( 'validateAuthData invalid signature id' , async ( ) => {
1676
1673
const authData = {
1677
1674
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' ,
1697
1676
timestamp : 1565257031287 ,
1698
1677
signature : '1234' ,
1699
1678
salt : 'DzqqrQ==' ,
1700
- bundleId : 'cloud.xtralife.gamecenterauth ' ,
1679
+ bundleId : 'com.example.com ' ,
1701
1680
} ;
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
+ ) ;
1709
1684
} ) ;
1710
1685
1711
1686
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
+ ) ;
1729
1713
} ) ;
1730
1714
} ) ;
1731
1715
0 commit comments