|
9 | 9 | validateExternalUrl, |
10 | 10 | validateFileExtension, |
11 | 11 | validateGoogleCalendarId, |
| 12 | + validateGoogleCloudLocation, |
| 13 | + validateGoogleCloudProject, |
12 | 14 | validateHostname, |
13 | 15 | validateImageUrl, |
14 | 16 | validateInteger, |
@@ -1458,6 +1460,19 @@ describe('validateAwsRegion', () => { |
1458 | 1460 | }) |
1459 | 1461 | }) |
1460 | 1462 |
|
| 1463 | + describe('valid European Sovereign Cloud regions', () => { |
| 1464 | + it.concurrent('should accept eusc-de-east-1', () => { |
| 1465 | + const result = validateAwsRegion('eusc-de-east-1') |
| 1466 | + expect(result.isValid).toBe(true) |
| 1467 | + expect(result.sanitized).toBe('eusc-de-east-1') |
| 1468 | + }) |
| 1469 | + |
| 1470 | + it.concurrent('should reject a malformed eusc region', () => { |
| 1471 | + expect(validateAwsRegion('eusc-de-east').isValid).toBe(false) |
| 1472 | + expect(validateAwsRegion('eusc-deu-east-1').isValid).toBe(false) |
| 1473 | + }) |
| 1474 | + }) |
| 1475 | + |
1461 | 1476 | describe('valid China regions', () => { |
1462 | 1477 | it.concurrent('should accept cn-north-1', () => { |
1463 | 1478 | const result = validateAwsRegion('cn-north-1') |
@@ -1561,6 +1576,91 @@ describe('validateAwsRegion', () => { |
1561 | 1576 | }) |
1562 | 1577 | }) |
1563 | 1578 |
|
| 1579 | +describe('validateGoogleCloudLocation', () => { |
| 1580 | + describe('valid locations', () => { |
| 1581 | + it.concurrent.each([ |
| 1582 | + 'us-central1', |
| 1583 | + 'us-east5', |
| 1584 | + 'europe-west4', |
| 1585 | + 'northamerica-northeast1', |
| 1586 | + 'southamerica-east1', |
| 1587 | + 'asia-northeast3', |
| 1588 | + 'australia-southeast2', |
| 1589 | + 'africa-south1', |
| 1590 | + 'me-central2', |
| 1591 | + 'global', |
| 1592 | + ])('should accept %s', (location) => { |
| 1593 | + const result = validateGoogleCloudLocation(location) |
| 1594 | + expect(result.isValid).toBe(true) |
| 1595 | + expect(result.sanitized).toBe(location) |
| 1596 | + }) |
| 1597 | + }) |
| 1598 | + |
| 1599 | + describe('hostname injection', () => { |
| 1600 | + it.concurrent.each([ |
| 1601 | + 'attacker.example.com/x', |
| 1602 | + 'us-central1/../attacker.tld', |
| 1603 | + 'us-central1:8080', |
| 1604 | + 'user@attacker.tld', |
| 1605 | + 'us-central1?a=b', |
| 1606 | + 'us-central1#frag', |
| 1607 | + 'us central1', |
| 1608 | + 'us-central1\n', |
| 1609 | + 'US-CENTRAL1', |
| 1610 | + '../us-central1', |
| 1611 | + ])('should reject %j', (location) => { |
| 1612 | + const result = validateGoogleCloudLocation(location) |
| 1613 | + expect(result.isValid).toBe(false) |
| 1614 | + }) |
| 1615 | + }) |
| 1616 | + |
| 1617 | + it.concurrent('should reject empty and missing values', () => { |
| 1618 | + expect(validateGoogleCloudLocation('').isValid).toBe(false) |
| 1619 | + expect(validateGoogleCloudLocation(null).isValid).toBe(false) |
| 1620 | + expect(validateGoogleCloudLocation(undefined).isValid).toBe(false) |
| 1621 | + }) |
| 1622 | + |
| 1623 | + it.concurrent('should name the parameter in the error', () => { |
| 1624 | + const result = validateGoogleCloudLocation('bad host', 'vertexLocation') |
| 1625 | + expect(result.error).toContain('vertexLocation') |
| 1626 | + }) |
| 1627 | +}) |
| 1628 | + |
| 1629 | +describe('validateGoogleCloudProject', () => { |
| 1630 | + describe('valid projects', () => { |
| 1631 | + it.concurrent.each(['my-project', 'sim-prod-1', 'abcdef', '123456789012'])( |
| 1632 | + 'should accept %s', |
| 1633 | + (project) => { |
| 1634 | + const result = validateGoogleCloudProject(project) |
| 1635 | + expect(result.isValid).toBe(true) |
| 1636 | + expect(result.sanitized).toBe(project) |
| 1637 | + } |
| 1638 | + ) |
| 1639 | + }) |
| 1640 | + |
| 1641 | + describe('path injection and malformed ids', () => { |
| 1642 | + it.concurrent.each([ |
| 1643 | + 'my-project/../../other', |
| 1644 | + 'my-project:alias', |
| 1645 | + 'my project', |
| 1646 | + 'My-Project', |
| 1647 | + '1project', |
| 1648 | + 'my-project-', |
| 1649 | + 'abc', |
| 1650 | + 'a'.repeat(31), |
| 1651 | + ])('should reject %j', (project) => { |
| 1652 | + const result = validateGoogleCloudProject(project) |
| 1653 | + expect(result.isValid).toBe(false) |
| 1654 | + }) |
| 1655 | + }) |
| 1656 | + |
| 1657 | + it.concurrent('should reject empty and missing values', () => { |
| 1658 | + expect(validateGoogleCloudProject('').isValid).toBe(false) |
| 1659 | + expect(validateGoogleCloudProject(null).isValid).toBe(false) |
| 1660 | + expect(validateGoogleCloudProject(undefined).isValid).toBe(false) |
| 1661 | + }) |
| 1662 | +}) |
| 1663 | + |
1564 | 1664 | describe('validateS3BucketName', () => { |
1565 | 1665 | describe('valid bucket names', () => { |
1566 | 1666 | it.concurrent('should accept simple bucket name', () => { |
|
0 commit comments