|
1 | | -import { EJSON, ObjectId } from 'bson'; |
| 1 | +import { BSONRegExp, Code, Double, EJSON, Int32, MaxKey, MinKey, ObjectId } from 'bson'; |
2 | 2 | import { expect } from 'chai'; |
3 | 3 | import * as sinon from 'sinon'; |
4 | 4 | import { Readable, Writable } from 'stream'; |
@@ -1612,3 +1612,125 @@ describe('class MongoLogger', function () { |
1612 | 1612 | } |
1613 | 1613 | }); |
1614 | 1614 | }); |
| 1615 | + |
| 1616 | +describe('stringifyWithMaxLen', function () { |
| 1617 | + describe('when stringifying a string field', function () { |
| 1618 | + it('does not prematurely redact the next key', function () { |
| 1619 | + const doc = { |
| 1620 | + a: 'aaa', |
| 1621 | + b: 'bbb' |
| 1622 | + }; |
| 1623 | + |
| 1624 | + const returnVal = stringifyWithMaxLen(doc, 13); |
| 1625 | + expect(returnVal).to.contain('"b...'); |
| 1626 | + }); |
| 1627 | + }); |
| 1628 | + |
| 1629 | + describe('when stringifying a number field', function () { |
| 1630 | + it('does not prematurely redact the next key', function () { |
| 1631 | + const doc = { |
| 1632 | + a: 1000, |
| 1633 | + b: 'bbb' |
| 1634 | + }; |
| 1635 | + const returnVal = stringifyWithMaxLen(doc, 12); |
| 1636 | + |
| 1637 | + expect(returnVal).to.contain('"b...'); |
| 1638 | + }); |
| 1639 | + }); |
| 1640 | + |
| 1641 | + describe('when stringifying a bigint field', function () { |
| 1642 | + it('does not prematurely redact the next key', function () { |
| 1643 | + const doc = { |
| 1644 | + a: 1000n, |
| 1645 | + b: 'bbb' |
| 1646 | + }; |
| 1647 | + const returnVal = stringifyWithMaxLen(doc, 12); |
| 1648 | + |
| 1649 | + expect(returnVal).to.contain('"b...'); |
| 1650 | + }); |
| 1651 | + }); |
| 1652 | + |
| 1653 | + describe('when stringifying a BSON Code field', function () { |
| 1654 | + it('does not prematurely redact the next key', function () { |
| 1655 | + const doc = { |
| 1656 | + c: new Code('console.log();'), |
| 1657 | + b: 'bbb' |
| 1658 | + }; |
| 1659 | + const returnVal = stringifyWithMaxLen(doc, 34); |
| 1660 | + |
| 1661 | + expect(returnVal).to.contain('"b...'); |
| 1662 | + }); |
| 1663 | + }); |
| 1664 | + |
| 1665 | + describe('when stringifying a BSON Double field', function () { |
| 1666 | + it('does not prematurely redact the next key', function () { |
| 1667 | + const doc = { |
| 1668 | + c: new Double(123.1), |
| 1669 | + b: 'bbb' |
| 1670 | + }; |
| 1671 | + const returnVal = stringifyWithMaxLen(doc, 13); |
| 1672 | + |
| 1673 | + expect(returnVal).to.contain('"b...'); |
| 1674 | + }); |
| 1675 | + }); |
| 1676 | + |
| 1677 | + describe('when stringifying a BSON Int32 field', function () { |
| 1678 | + it('does not prematurely redact the next key', function () { |
| 1679 | + const doc = { |
| 1680 | + c: new Int32(123), |
| 1681 | + b: 'bbb' |
| 1682 | + }; |
| 1683 | + const returnVal = stringifyWithMaxLen(doc, 11); |
| 1684 | + |
| 1685 | + expect(returnVal).to.contain('"b...'); |
| 1686 | + }); |
| 1687 | + }); |
| 1688 | + |
| 1689 | + describe('when stringifying a BSON MaxKey field', function () { |
| 1690 | + it('does not prematurely redact the next key', function () { |
| 1691 | + const doc = { |
| 1692 | + c: new MaxKey(), |
| 1693 | + b: 'bbb' |
| 1694 | + }; |
| 1695 | + const returnVal = stringifyWithMaxLen(doc, 21); |
| 1696 | + |
| 1697 | + expect(returnVal).to.contain('"b...'); |
| 1698 | + }); |
| 1699 | + }); |
| 1700 | + |
| 1701 | + describe('when stringifying a BSON MinKey field', function () { |
| 1702 | + it('does not prematurely redact the next key', function () { |
| 1703 | + const doc = { |
| 1704 | + c: new MinKey(), |
| 1705 | + b: 'bbb' |
| 1706 | + }; |
| 1707 | + const returnVal = stringifyWithMaxLen(doc, 21); |
| 1708 | + |
| 1709 | + expect(returnVal).to.contain('"b...'); |
| 1710 | + }); |
| 1711 | + }); |
| 1712 | + |
| 1713 | + describe('when stringifying a BSON ObjectId field', function () { |
| 1714 | + it('does not prematurely redact the next key', function () { |
| 1715 | + const doc = { |
| 1716 | + c: new ObjectId(), |
| 1717 | + b: 'bbb' |
| 1718 | + }; |
| 1719 | + const returnVal = stringifyWithMaxLen(doc, 43); |
| 1720 | + |
| 1721 | + expect(returnVal).to.contain('"b...'); |
| 1722 | + }); |
| 1723 | + }); |
| 1724 | + |
| 1725 | + describe('when stringifying a BSON BSONRegExp field', function () { |
| 1726 | + it('does not prematurely redact the next key', function () { |
| 1727 | + const doc = { |
| 1728 | + c: new BSONRegExp('testRegex', 'is'), |
| 1729 | + b: 'bbb' |
| 1730 | + }; |
| 1731 | + const returnVal = stringifyWithMaxLen(doc, 69); |
| 1732 | + |
| 1733 | + expect(returnVal).to.contain('"b...'); |
| 1734 | + }); |
| 1735 | + }); |
| 1736 | +}); |
0 commit comments