Commit 42a1fd4
Skip binary files in DB cache sync (kptdev#437)
* Skip binary files and NUL bytes in DB cache sync
Binary files with invalid UTF-8 and files containing NUL bytes
(0x00) both cause PostgreSQL TEXT columns to reject the INSERT.
While utf8.ValidString() catches invalid UTF-8, NUL is technically
valid UTF-8 per RFC 3629 but PostgreSQL still rejects it.
Add strings.Contains(val, "\x00") check alongside utf8.ValidString()
to also filter files containing NUL bytes. Add 5 test cases covering:
mixed text/binary files, all text files, all binary files, empty
resources, and NUL byte content that passes utf8.ValidString().
Fixes: nephio-project/nephio#1040
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
* Also validate resource_key (file path) for PostgreSQL TEXT safety
resource_key is also a TEXT column, so file paths with invalid UTF-8
(e.g. Latin-1 encoded paths from older systems) would crash the INSERT.
Added validation for both key and value, plus a test case.
Fixes: nephio-project/nephio#1040
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
* Add defer Close and mock CacheInstance to test functions
The 6 test functions added for binary file filtering were missing
defer testRepo.Close(ctx) after OpenRepository, which could leak
resources if assertions fail. Also added mock CacheInstance setup
since Close() internally calls pkgScanRowsFromDB which requires
CacheInstance to resolve repository references.
Follows the same pattern used in TestRepositorySync_SyncOnce and
TestNewRepositorySync.
Fixes: nephio-project/nephio#1040
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
* Add nil guard for GetResources and improve test coverage
- Guard against nil return from GetResources() to prevent panic,
since the PackageRevision interface contract allows (nil, nil)
- Add TestCacheExternalPRs_NilResources to cover the nil guard path
- Use testify idiomatic assertions (t.Empty, t.Len) for consistency
with the rest of the dbcache test suite
Fixes: nephio-project/nephio#1040
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
---------
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Co-authored-by: Liam Fallon <35595825+liamfallon@users.noreply.github.com>1 parent eed4714 commit 42a1fd4
2 files changed
Lines changed: 626 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
224 | 226 | | |
225 | 227 | | |
226 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
227 | 247 | | |
228 | 248 | | |
229 | 249 | | |
| |||
239 | 259 | | |
240 | 260 | | |
241 | 261 | | |
242 | | - | |
| 262 | + | |
243 | 263 | | |
244 | 264 | | |
245 | 265 | | |
| |||
0 commit comments