@@ -1789,6 +1789,40 @@ func TestPurgeWithSomeInvalidDocs(t *testing.T) {
1789
1789
rest .RequireStatus (t , rt .SendAdminRequest ("PUT" , "/{{.keyspace}}/doc2" , `{"moo":"car"}` ), 409 )
1790
1790
}
1791
1791
1792
+ // TestPurgeWithOldAttachment ensures that purging a document with an attachment actually removes it and a recreated document does not have the old attachment.
1793
+ func TestPurgeWithOldAttachment (t * testing.T ) {
1794
+ rt := rest .NewRestTester (t , nil )
1795
+ defer rt .Close ()
1796
+
1797
+ _ = rt .PutDocWithAttachment ("doc1" , `{"foo":"doc1"}` , "att1" , "b25lCg==" )
1798
+
1799
+ rawBody , rawXattrs , _ , err := rt .GetSingleDataStore ().GetWithXattrs (t .Context (), "doc1" , []string {base .SyncXattrName , base .GlobalXattrName })
1800
+ require .NoError (t , err )
1801
+ assert .NotNil (t , rawBody )
1802
+ assert .NotNil (t , rawXattrs )
1803
+
1804
+ response := rt .SendAdminRequest ("POST" , "/{{.keyspace}}/_purge" , `{"doc1":["*"]}` )
1805
+ rest .RequireStatus (t , response , http .StatusOK )
1806
+ var body db.Body
1807
+ require .NoError (t , base .JSONUnmarshal (response .Body .Bytes (), & body ))
1808
+ assert .Equal (t , db.Body {"purged" : map [string ]any {"doc1" : []interface {}{"*" }}}, body )
1809
+
1810
+ // inspect bucket doc to ensure SG's xattrs are gone
1811
+ rawBody , rawXattrs , _ , err = rt .GetSingleDataStore ().GetWithXattrs (t .Context (), "doc1" , []string {base .SyncXattrName , base .GlobalXattrName })
1812
+ assert .Error (t , err )
1813
+ assert .True (t , base .IsDocNotFoundError (err ))
1814
+ assert .Nil (t , rawBody )
1815
+ assert .Empty (t , rawXattrs )
1816
+
1817
+ // Here we're overwriting any previous global sync that may exist, so attachments being resurrected aren't an actual issue for us.
1818
+ _ = rt .PutDocDirectly ("doc1" , db.Body {"foo" : "doc1" })
1819
+
1820
+ rawBody , rawXattrs , _ , err = rt .GetSingleDataStore ().GetWithXattrs (t .Context (), "doc1" , []string {base .SyncXattrName , base .GlobalXattrName })
1821
+ require .NoError (t , err )
1822
+ assert .NotNil (t , rawBody )
1823
+ assert .NotNil (t , rawXattrs )
1824
+ }
1825
+
1792
1826
// TestRawRedaction tests the /_raw endpoint with and without redaction
1793
1827
// intentionally does string matching on redactable strings to avoid any regressions if we move around metadata without updating the test
1794
1828
func TestRawRedaction (t * testing.T ) {
0 commit comments