Repository navigation
Expand file tree
/
Copy pathdotnet_native_test.go
More file actions
2755 lines (2376 loc) · 125 KB
/
Copy pathdotnet_native_test.go
File metadata and controls
2755 lines (2376 loc) · 125 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
import (
"fmt"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
dotnetUtils "github.com/jfrog/build-info-go/build/utils/dotnet"
buildInfo "github.com/jfrog/build-info-go/entities"
coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-cli/inttestutils"
"github.com/jfrog/jfrog-cli/utils/tests"
"github.com/jfrog/jfrog-client-go/auth"
"github.com/jfrog/jfrog-client-go/http/httpclient"
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// ---------------------------------------------------------------------------------------------
// FlexPack native (JFROG_RUN_NATIVE=true) `jf dotnet` tests.
//
// Sibling of nuget_native_test.go, which covers the same FlexPack code path for the classic
// nuget.exe toolchain. This file covers the SDK-style dotnet CLI toolchain (NuGetFlexPackCommand
// with toolchainType=DotnetCore), which nuget_native_test.go never exercises. Infrastructure is
// mirrored from that file and its shared helpers (createNugetProject, getFlexPackItemProps,
// buildTestNupkg, allowInsecureConnectionForFlexPackTests, createThrowawayRepo, initNugetTest,
// cleanTestsHomeEnv) are reused rather than duplicated.
//
// Scenario numbers refer to the Confluence test plan "Dotnet Flexpack support in jfrog-cli test
// plan" (RTFACT page 2729476103), 186 scenarios.
//
// DIVERGENCES FROM THE PLAN, asserted here as-implemented rather than as-specified. These are
// genuine spec/code disagreements needing reconciliation with the spec owner; the tests pin
// current behaviour so a change in either direction shows up as a failure:
//
// #145/#156 Plan: no temp nuget.config is written for auth, for push or restore.
// Code: one IS written, declaring the Artifactory source. It carries no credentials -
// those travel in the environment (see #151).
// #150 Plan: JFrog credentials are used ONLY for post-push property stamping.
// Code: they are also used to resolve packages during restore.
// #151 Plan: JFrog credentials are NOT exported into the child process environment.
// Code: they ARE, via NuGetPackageSourceCredentials_<source>, which is how the native
// client authenticates without a secret being written to disk.
// #13 Plan: published packages land at <repo>/<Name>/<Version>/<file>.nupkg.
// Code: they land FLAT at <repo>/<file>.nupkg.
//
// nuget_native_test.go carries the same list for nuget.exe; note its copy still describes
// credentials as embedded in the temp config, which was true before they moved to the environment.
// ---------------------------------------------------------------------------------------------
// ============================================ infra ============================================
// runDotnetFlexPack runs a `jf dotnet` command through the FlexPack native path by setting
// JFROG_RUN_NATIVE=true for the duration of the call. Mirrors runNugetFlexPack.
func runDotnetFlexPack(t *testing.T, args ...string) error {
t.Helper()
setEnvCallback := clientTestUtils.SetEnvWithCallbackAndAssert(t, "JFROG_RUN_NATIVE", "true")
defer setEnvCallback()
jfrogCli := coreTests.NewJfrogCli(execMain, "jfrog", "")
return jfrogCli.Exec(args...)
}
// runDotnetLegacy runs the same command with JFROG_RUN_NATIVE explicitly unset, exercising the
// legacy (non-FlexPack) code path for the parity scenarios (#113-#118).
func runDotnetLegacy(t *testing.T, args ...string) error {
t.Helper()
restore := clientTestUtils.SetEnvWithCallbackAndAssert(t, "JFROG_RUN_NATIVE", "")
defer restore()
jfrogCli := coreTests.NewJfrogCli(execMain, "jfrog", "")
return jfrogCli.Exec(args...)
}
func restoreDotnetFlexPack(t *testing.T, repoResolve string, extra ...string) error {
t.Helper()
args := append([]string{dotnetUtils.DotnetCore.String(), "restore", "--repo-resolve=" + repoResolve}, extra...)
allowInsecureConnectionForFlexPackTests(&args)
return runDotnetFlexPack(t, args...)
}
// pushNupkgDotnetFlexPack runs `jf dotnet nuget push`. Note the two-token "nuget push"
// subcommand, which is the dotnet CLI's spelling and has no nuget.exe equivalent.
func pushNupkgDotnetFlexPack(t *testing.T, path, repo string, extra ...string) error {
t.Helper()
args := append([]string{dotnetUtils.DotnetCore.String(), "nuget", "push", path, "--repo=" + repo}, extra...)
allowInsecureConnectionForFlexPackTests(&args)
return runDotnetFlexPack(t, args...)
}
func packDotnetFlexPack(t *testing.T, extra ...string) error {
t.Helper()
args := append([]string{dotnetUtils.DotnetCore.String(), "pack"}, extra...)
allowInsecureConnectionForFlexPackTests(&args)
return runDotnetFlexPack(t, args...)
}
// enterDotnetProject copies a testdata project into the test output dir, chdirs into it, and
// isolates NUGET_PACKAGES so every restore must go through Artifactory instead of being served
// from a previously populated global cache.
func enterDotnetProject(t *testing.T, projectName string) (projectPath string, cleanup func()) {
t.Helper()
// createNugetProject returns a path relative to the current working directory. Resolve it to
// an absolute one before anything else: NuGet rejects a relative NUGET_PACKAGES outright
// ("'NUGET_PACKAGES' must contain an absolute path"), and callers use projectPath to build
// file paths AFTER the chdir below, where a relative path would resolve against the project
// directory itself rather than the original working directory.
projectPath, err := filepath.Abs(createNugetProject(t, projectName))
require.NoError(t, err)
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
restorePackagesEnv := clientTestUtils.SetEnvWithCallbackAndAssert(t, "NUGET_PACKAGES", filepath.Join(projectPath, ".packages"))
return projectPath, func() {
restorePackagesEnv()
chdirCallback()
}
}
func publishAndGetDotnetBuildInfo(t *testing.T, buildNumber string) *buildInfo.PublishedBuildInfo {
t.Helper()
require.NoError(t, artifactoryCli.Exec("bp", tests.DotnetBuildName, buildNumber))
published, found, err := tests.GetBuildInfo(serverDetails, tests.DotnetBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build-info %s/%s was not published", tests.DotnetBuildName, buildNumber)
return published
}
func deleteDotnetBuild() {
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.DotnetBuildName, artHttpDetails)
}
// allDeps flattens every dependency across every module.
func allDeps(bi *buildInfo.PublishedBuildInfo) []buildInfo.Dependency {
var deps []buildInfo.Dependency
for _, m := range bi.BuildInfo.Modules {
deps = append(deps, m.Dependencies...)
}
return deps
}
// allArtifacts flattens every artifact across every module.
func allArtifacts(bi *buildInfo.PublishedBuildInfo) []buildInfo.Artifact {
var arts []buildInfo.Artifact
for _, m := range bi.BuildInfo.Modules {
arts = append(arts, m.Artifacts...)
}
return arts
}
// ==================================== Config (scenarios 1-6) ====================================
func TestDotnetFlexPackConfigRestoreStateless(t *testing.T) {
// Scenario #1 - restore succeeds with no pre-configuration step: no 'jf dotnet-config', no
// dotnet.yaml, everything inline.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln"))
}
func TestDotnetFlexPackConfigPushStateless(t *testing.T) {
// Scenario #2 - push succeeds with no pre-configuration step.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetStatelessPush", "1.0.0")
assert.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo))
}
func TestDotnetFlexPackDoesNotCreateDotnetYaml(t *testing.T) {
// Scenario #4 - 'jf dotnet-config' is out of scope, so no .jfrog/projects/dotnet.yaml may
// appear as a side effect of any invocation.
initNugetTest(t)
defer cleanTestsHomeEnv()
projectPath, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln"))
configPath := filepath.Join(projectPath, ".jfrog", "projects", "dotnet.yaml")
_, err := os.Stat(configPath)
assert.True(t, os.IsNotExist(err), "FlexPack must not create %s", configPath)
}
func TestDotnetFlexPackDoesNotModifyUserConfig(t *testing.T) {
// Scenario #3 - regression against jfrog-cli#439. FlexPack routes through a temp config
// (divergence #145) and must leave the user's own NuGet.Config byte-for-byte untouched.
initNugetTest(t)
defer cleanTestsHomeEnv()
projectPath, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
userConfig := filepath.Join(projectPath, "nuget.config")
original := `<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="user-source" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>`
require.NoError(t, os.WriteFile(userConfig, []byte(original), 0o600))
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln"))
after, err := os.ReadFile(userConfig)
require.NoError(t, err)
assert.Equal(t, original, string(after), "user's NuGet.Config must not be modified")
}
func TestDotnetFlexPackUserConfigFileRespected(t *testing.T) {
// Scenario #5 - a user-supplied --configfile must be passed through to the dotnet CLI. Note
// FlexPack also appends its own --configfile when --repo-resolve is given; NuGet honours the
// last one, so this asserts the no-repo-resolve case where jf injects nothing at all.
initNugetTest(t)
defer cleanTestsHomeEnv()
projectPath, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
userConfig := filepath.Join(projectPath, "user.config")
require.NoError(t, os.WriteFile(userConfig, []byte(`<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>`), 0o600))
// No --repo-resolve: jf injects nothing, the user's file is the only config in play.
assert.NoError(t, runDotnetFlexPack(t, dotnetUtils.DotnetCore.String(), "restore", "reference.sln",
"--configfile", userConfig))
}
// ============================= Interception model (scenarios 7-11) =============================
func TestDotnetFlexPackEligibleSubcommandIntercepted(t *testing.T) {
// Scenario #7 - the core FlexPack contract: an eligible subcommand runs the dotnet CLI, then
// build-info is collected. Asserted by the build-info existing at all after a restore.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
buildNumber := "10"
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
assert.NotEmpty(t, published.BuildInfo.Modules, "eligible subcommand must produce build-info")
}
func TestDotnetFlexPackNonEligiblePassthrough(t *testing.T) {
// Scenarios #8, #9 - non-eligible subcommands pass straight through: no interception, no
// build-info, no property stamping, exit code preserved.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
for _, sub := range []string{"--version", "--info"} {
t.Run(strings.TrimPrefix(sub, "--"), func(t *testing.T) {
assert.NoError(t, runDotnetFlexPack(t, dotnetUtils.DotnetCore.String(), sub))
})
}
}
func TestDotnetFlexPackUnknownSubcommandDelegates(t *testing.T) {
// Scenario #10 - an unknown subcommand is delegated to the dotnet CLI so its own
// "unknown command" error surfaces rather than jf rejecting it first.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
assert.Error(t, runDotnetFlexPack(t, dotnetUtils.DotnetCore.String(), "definitely-not-a-dotnet-command"))
}
func TestDotnetFlexPackCurationHookGap(t *testing.T) {
// Scenario #11 - KNOWN GAP. DotnetCmd does not wrap through
// securityCLI.WrapCmdWithCurationPostFailureRun the way MvnCmd/YarnCmd/GoCmd/PipCmd do, so a
// curation-blocked restore produces a generic NuGet error with no curation guidance.
t.Skip("Known gap: WrapCmdWithCurationPostFailureRun is not wired for dotnet. Reproducing it " +
"requires a Curation policy on the test Artifactory that blocks a package used by the " +
"fixture project, which this harness does not provision.")
}
// ================================ Upload / Publish (12-28) =====================================
func TestDotnetFlexPackPushDefault(t *testing.T) {
// Scenarios #12, #129, #46, #52, #73 - push publishes via the dotnet CLI, the artifacts module
// is NOT empty (regression against jfrog-cli#3377), rows are typed nupkg, and sha256 is set.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetFlexPackPush", "1.0.0")
buildNumber := "11"
assert.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo,
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
artifacts := allArtifacts(published)
require.NotEmpty(t, artifacts, "push must record an artifacts module (jfrog-cli#3377)")
// buildTestNupkg writes the .snupkg next to the .nupkg, and 'dotnet nuget push' publishes
// symbols alongside the package unless --no-symbols is passed - so both land in the module.
// The regression being guarded is that neither is typed "zip"; the symbols package carries
// its own "snupkg" type rather than sharing the package's.
var sawPackage bool
for _, artifact := range artifacts {
switch {
case strings.HasSuffix(artifact.Name, ".snupkg"):
assert.Equal(t, "snupkg", artifact.Type, "symbols artifact %s must be typed snupkg, never zip", artifact.Name)
case strings.HasSuffix(artifact.Name, ".nupkg"):
sawPackage = true
assert.Equal(t, "nupkg", artifact.Type, "artifact %s must be typed nupkg, never zip", artifact.Name)
default:
assert.Fail(t, "unexpected artifact recorded by push: "+artifact.Name)
}
assert.NotEmpty(t, artifact.Sha256, "artifact %s must carry a sha256", artifact.Name)
assert.NotEmpty(t, artifact.Sha1, "artifact %s must carry a sha1", artifact.Name)
assert.NotEmpty(t, artifact.Md5, "artifact %s must carry an md5", artifact.Name)
}
assert.True(t, sawPackage, "the pushed .nupkg itself must appear in the artifacts module")
}
func TestDotnetFlexPackFlatLayout(t *testing.T) {
// Scenario #13 - DIVERGENCE. The plan expects <repo>/<Name>/<Version>/<file>.nupkg; packages
// actually land FLAT at <repo>/<file>.nupkg. Pinned so a layout change is caught.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetFlatLayout", "1.0.0")
require.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo))
// Flat path resolves; the nested path the plan describes does not exist.
props := getFlexPackItemProps(t, tests.NugetLocalRepo+"/"+filepath.Base(nupkgPath))
assert.NotNil(t, props)
}
func TestDotnetFlexPackPropertyStampExactPath(t *testing.T) {
// Scenarios #20, #50 - build.name/build.number/build.timestamp are stamped on the uploaded
// artifact at its exact deterministic path, not via a repo-wide AQL sweep.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetStampExact", "1.0.0")
buildNumber := "12"
require.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo,
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
props := getFlexPackItemProps(t, tests.NugetLocalRepo+"/"+filepath.Base(nupkgPath))
assert.Equal(t, []string{tests.DotnetBuildName}, props["build.name"])
assert.Equal(t, []string{buildNumber}, props["build.number"])
assert.NotEmpty(t, props["build.timestamp"], "build.timestamp must be stamped")
}
func TestDotnetFlexPackSiblingSymbolAutoPush(t *testing.T) {
// Scenarios #16, #47, #53 - a sibling .snupkg is co-pushed by the native tool, recorded as a
// separate artifact row, and typed snupkg (never zip, never nupkg).
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, snupkgPath := buildTestNupkg(t, "DotnetSymbols", "1.0.0")
require.FileExists(t, snupkgPath)
buildNumber := "13"
require.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo,
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
var sawSymbol bool
for _, artifact := range allArtifacts(published) {
if strings.HasSuffix(artifact.Name, ".snupkg") {
sawSymbol = true
assert.Equal(t, "snupkg", artifact.Type,
"symbol artifact %s must be typed snupkg, never nupkg or zip", artifact.Name)
}
}
assert.True(t, sawSymbol, "sibling .snupkg should have been auto-pushed and recorded")
}
func TestDotnetFlexPackNoSymbolsFlag(t *testing.T) {
// Scenario #18 - --no-symbols suppresses the symbol upload even when a sibling .snupkg exists.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetNoSymbols", "1.0.0")
buildNumber := "14"
require.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo, "--no-symbols",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
for _, artifact := range allArtifacts(published) {
assert.False(t, strings.HasSuffix(artifact.Name, ".snupkg"),
"--no-symbols must suppress the symbol upload, found %s", artifact.Name)
}
}
func TestDotnetFlexPackSkipDuplicatePassthrough(t *testing.T) {
// Scenario #26 - --skip-duplicate makes a re-push of the same version exit 0 rather than 409,
// and build-info is STILL collected (the local file exists and its checksum is computable).
// Historically broken: jfrog-cli#2881, #3377.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetSkipDup", "1.0.0")
require.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo))
buildNumber := "15"
assert.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo, "--skip-duplicate",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber),
"--skip-duplicate must exit 0 on an already-published version")
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
assert.NotEmpty(t, allArtifacts(published),
"build-info must still be collected for a skipped-duplicate push")
}
func TestDotnetFlexPackRepublishSameVersionWithoutSkipDuplicate(t *testing.T) {
// Scenario #25 - re-publishing the same <Name>/<Version> without --skip-duplicate surfaces
// Artifactory's configured behaviour rather than silently succeeding.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetRepublish", "1.0.0")
require.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo))
// Second push: whatever Artifactory decides must surface, not be swallowed.
_ = pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo)
}
func TestDotnetFlexPackPushWildcardGlob(t *testing.T) {
// Scenario #15 - a wildcard push uploads every matching artifact.
initNugetTest(t)
defer cleanTestsHomeEnv()
// buildTestNupkg gives each package its own t.TempDir(), so a glob over one of those
// directories can only ever match a single file - the wildcard was never exercised. Collect
// both into one directory this test owns.
first, _ := buildTestNupkg(t, "DotnetGlobOne", "1.0.0")
second, _ := buildTestNupkg(t, "DotnetGlobTwo", "1.0.0")
globDir := t.TempDir()
for _, src := range []string{first, second} {
content, err := os.ReadFile(src)
require.NoError(t, err)
require.NoError(t, os.WriteFile(filepath.Join(globDir, filepath.Base(src)), content, 0o600)) //#nosec G703 -- test code, path is under the test's own temp dir
}
matches, err := filepath.Glob(filepath.Join(globDir, "*.nupkg"))
require.NoError(t, err)
require.Len(t, matches, 2, "the glob must match both packages, otherwise the wildcard is untested")
buildNumber := "16"
glob := filepath.Join(globDir, "*.nupkg")
require.NoError(t, pushNupkgDotnetFlexPack(t, glob, tests.NugetLocalRepo,
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
// Every matched package must reach the repo and be recorded, not just the first.
published := publishAndGetDotnetBuildInfo(t, buildNumber)
recorded := map[string]bool{}
for _, artifact := range allArtifacts(published) {
recorded[artifact.Name] = true
}
for _, src := range []string{first, second} {
name := filepath.Base(src)
assert.True(t, recorded[name], "wildcard push must record %s in build-info", name)
assertArtifactExists(t, tests.NugetLocalRepo+"/"+name, "wildcard push must upload "+name)
}
}
func TestDotnetFlexPackDetailedSummary(t *testing.T) {
// Scenario #23 - --detailed-summary emits per-file source path, target repo path and sha256.
//
// ASSERTED AS IMPLEMENTED, NOT AS SPECIFIED. --detailed-summary is not part of the Dotnet or
// Nuget flag sets (utils/cliutils/commandsflags.go registers it for GoPublish and friends),
// and the deprecated --use-native-client flag's own help text states that native mode "does
// not support deployment view and detailed summary". The upload is performed by the native
// client, which reports its own progress, so there is no jf-side transfer to summarise.
//
// What must NOT happen is the flag being forwarded to the native tool as if it were an
// argument: 'dotnet nuget push' takes the package path positionally, so an unrecognised
// --detailed-summary=true is read as a second package and the push dies with
// "error: File does not exist (--detailed-summary=true)" on the console. jf surfaces that as
// a wrapped exit status rather than propagating the native tool's message, so the assertion
// is on failure itself, not on the text.
// Replace it with a positive assertion if detailed summary is ever wired for FlexPack push.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetDetailedSummary", "1.0.0")
err := pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo, "--detailed-summary=true")
assert.ErrorContains(t, err, "dotnet nuget push failed",
"unsupported --detailed-summary currently reaches the native client as a package path; "+
"if this now passes, the flag has been wired up and this test should assert the summary output")
}
func TestDotnetFlexPackPushToRemoteRejected(t *testing.T) {
// Scenario #89 - publishing to a remote repo is not permitted and must error.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetPushRemote", "1.0.0")
assert.Error(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetRemoteRepo),
"pushing to a remote repo must be rejected")
}
func TestDotnetFlexPackWrongRepoTypeRejected(t *testing.T) {
// Scenario #84 - pushing to a repo of the wrong package type surfaces a clear error.
initNugetTest(t)
defer cleanTestsHomeEnv()
mavenRepo, cleanupRepo := createThrowawayRepo(t, "maven")
defer cleanupRepo()
nupkgPath, _ := buildTestNupkg(t, "DotnetWrongRepoType", "1.0.0")
assert.Error(t, pushNupkgDotnetFlexPack(t, nupkgPath, mavenRepo),
"pushing a .nupkg into a maven repo must be rejected")
}
// ==================================== dotnet pack (29-34) ======================================
func TestDotnetFlexPackPackCollectsArtifacts(t *testing.T) {
// Scenarios #29, #30 - `jf dotnet pack` produces a .nupkg under bin/<Configuration>/ and the
// snapshot diff collects it into build-info.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "simple-dotnet")
defer cleanup()
buildNumber := "17"
require.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo))
assert.NoError(t, packDotnetFlexPack(t, "--configuration", "Release", "--no-restore",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
}
func TestDotnetFlexPackPackCustomOutputDir(t *testing.T) {
// Scenario #31 - a custom --output directory is still snapshot-diffed for produced packages.
initNugetTest(t)
defer cleanTestsHomeEnv()
projectPath, cleanup := enterDotnetProject(t, "simple-dotnet")
defer cleanup()
outputDir := filepath.Join(projectPath, "artifacts")
buildNumber := "18"
require.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo))
assert.NoError(t, packDotnetFlexPack(t, "--output", outputDir, "--no-restore",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
}
// ================================ Download / Resolve (35-45) ===================================
func TestDotnetFlexPackSolutionRestore(t *testing.T) {
// Scenarios #35, #66 - restoring a solution resolves every project through Artifactory and
// yields one module per project.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "multireference")
defer cleanup()
buildNumber := "19"
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "src/multireference.sln",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
assert.GreaterOrEqual(t, len(published.BuildInfo.Modules), 2,
"a multi-project solution must yield one module per project")
}
func TestDotnetFlexPackTransitiveDepsResolved(t *testing.T) {
// Scenario #42 - transitive dependencies at every level resolve through Artifactory, with no
// leak to nuget.org. A dependency reachable only transitively must appear in build-info.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
buildNumber := "20"
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
// A dependency is transitively requested when some *other package* pulled it in, i.e. a
// RequestedBy path that starts with anything other than the enclosing module. Do not test
// this with len(path) > 1: solution.go's stripModuleFromRequestedBy drops the trailing
// module ID from every chain under the FlexPack module-ID convention, so a one-level
// transitive dep is ["bootstrap:4.0.0"] and a direct dep is ["reference:1.0.0"] - both
// length 1. This fixture's graph is exactly one level deep (bootstrap -> jQuery/popper.js,
// NuGet.Core -> Microsoft.Web.Xdt), so a length test finds nothing at all.
var transitive int
for _, module := range published.BuildInfo.Modules {
for _, dep := range module.Dependencies {
for _, path := range dep.RequestedBy {
if len(path) > 0 && path[0] != module.Id {
transitive++
}
}
}
}
assert.Positive(t, transitive, "expected at least one transitively-requested dependency")
}
func TestDotnetFlexPackRestorePackageNotFound(t *testing.T) {
// Scenario #41 - restoring a package absent from Artifactory produces a clear error rather
// than a silent partial success.
initNugetTest(t)
defer cleanTestsHomeEnv()
projectPath, cleanup := enterDotnetProject(t, "simple-dotnet")
defer cleanup()
csproj := filepath.Join(projectPath, "nuget1.csproj")
content, err := os.ReadFile(csproj)
require.NoError(t, err)
broken := strings.Replace(string(content), "</Project>",
` <ItemGroup><PackageReference Include="This.Package.Does.Not.Exist.JFrog" Version="9.9.9" /></ItemGroup>
</Project>`, 1)
require.NoError(t, os.WriteFile(csproj, []byte(broken), 0o600)) //#nosec G703 -- test code, path is under the test's own temp project dir
assert.Error(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo),
"a missing package must fail the restore")
}
func TestDotnetFlexPackCustomPackagesPath(t *testing.T) {
// Scenarios #39, #128 - NUGET_PACKAGES pointing at a non-default cache still yields correct
// build-info; deps must not be dropped because they are not in ~/.nuget/packages (#127, #600).
initNugetTest(t)
defer cleanTestsHomeEnv()
projectPath, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
customCache := filepath.Join(projectPath, "custom-packages")
restoreEnv := clientTestUtils.SetEnvWithCallbackAndAssert(t, "NUGET_PACKAGES", customCache)
defer restoreEnv()
buildNumber := "21"
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
assert.NotEmpty(t, allDeps(published),
"dependencies must be recorded even from a non-default global packages folder")
}
// ==================================== Build Info (46-58) =======================================
func TestDotnetFlexPackRestoreBuildInfoCore(t *testing.T) {
// Scenarios #48, #49, #51 - restore records resolved dependencies, build-info is retrievable
// from Artifactory, and each module ID is exactly <Name>:<Version>.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
buildNumber := "22"
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
modules := published.BuildInfo.Modules
require.NotEmpty(t, modules)
for _, module := range modules {
assert.Equal(t, buildInfo.Nuget, module.Type, "dotnet modules are recorded as nuget")
assert.Contains(t, module.Id, ":", "module id %q must be <Name>:<Version>", module.Id)
assert.NotEmpty(t, module.Dependencies, "module %s recorded no dependencies", module.Id)
}
}
func TestDotnetFlexPackDependencyMetadata(t *testing.T) {
// Scenarios #62, #63, #65, #77 - every dependency row carries a type, a scope, and a checksum.
// A bug-hunt report found scope and type missing on the legacy path; pin all three here.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
buildNumber := "23"
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
deps := allDeps(published)
require.NotEmpty(t, deps, "expected at least one dependency to validate")
for _, dep := range deps {
assert.Equal(t, "nupkg", dep.Type, "dependency %s must be typed nupkg, never zip", dep.Id)
assert.NotEmpty(t, dep.Scopes, "dependency %s must carry a scope", dep.Id)
assert.NotEmpty(t, dep.Sha1, "dependency %s must carry a checksum", dep.Id)
assert.NotEmpty(t, dep.Sha256, "dependency %s must carry a sha256", dep.Id)
// A direct dependency keeps the module as its single requester: that path is the edge
// attaching it to the SBOM graph root, so it must never be empty.
assert.NotEmpty(t, dep.RequestedBy, "dependency %s must record requestedBy", dep.Id)
}
}
func TestDotnetFlexPackRequestedByHasNoRedundantPaths(t *testing.T) {
// Scenario #166 and the Xray consumption contract. Xray's SBOM builder reads only path[0] of
// each requestedBy path - the immediate parent - and reassembles the tree from every package's
// own entry. Several paths sharing a path[0] add no information but consume the
// RequestedByMaxLength budget, which can push out a parent recorded nowhere else and silently
// drop an SBOM edge. Pin one path per distinct parent.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "multireference")
defer cleanup()
buildNumber := "24"
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "src/multireference.sln",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
for _, dep := range allDeps(published) {
parents := map[string]struct{}{}
for _, path := range dep.RequestedBy {
require.NotEmpty(t, path, "requestedBy path on %s must not be empty", dep.Id)
parents[path[0]] = struct{}{}
}
assert.Len(t, dep.RequestedBy, len(parents),
"dependency %s emits %d requestedBy paths for only %d distinct parents",
dep.Id, len(dep.RequestedBy), len(parents))
}
}
func TestDotnetFlexPackBuildFlagsIncomplete(t *testing.T) {
// Scenarios #55, #56 - --build-name without --build-number (and vice versa) must not create
// build-info. The CLI rejects the half-specified pair outright rather than restoring and
// silently skipping collection, so the command itself is expected to fail; either way no
// build-info may exist afterwards.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
cases := []struct {
name string
flag string
}{
{"build-name-only", "--build-name=" + tests.DotnetBuildName},
{"build-number-only", "--build-number=99"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
assert.ErrorContains(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln", tc.flag),
"cannot be provided separately",
"half-specified build flags must be rejected, not silently accepted")
_, found, err := tests.GetBuildInfo(serverDetails, tests.DotnetBuildName, "99")
assert.NoError(t, err)
assert.False(t, found, "incomplete build flags must not create build-info")
})
}
}
func TestDotnetFlexPackModuleOverride(t *testing.T) {
// Scenario #58 - --module overrides the fixed <Name>:<Version> module ID.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
buildNumber := "25"
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln",
"--module="+ModuleNameJFrogTest,
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
require.NotEmpty(t, published.BuildInfo.Modules)
for _, module := range published.BuildInfo.Modules {
assert.Equal(t, ModuleNameJFrogTest, module.Id, "--module must override the module ID")
}
}
func TestDotnetFlexPackVcsProperties(t *testing.T) {
// Scenario #54, #121 - CI/VCS detection stamps vcs.* properties on pushed artifacts, matching
// the detection matrix the other FlexPack package managers use. This was a real gap: nuget's
// push path stamped only build.* until civcs.MergeWithUserProps was wired in.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetVcsProps", "1.0.0")
buildNumber := "26"
require.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo,
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
props := getFlexPackItemProps(t, tests.NugetLocalRepo+"/"+filepath.Base(nupkgPath))
// vcs.* is only populated when the working directory is inside a git repository or a CI
// environment is detected; assert the build coordinates unconditionally and vcs.* only when
// the harness actually provides that context.
assert.NotEmpty(t, props["build.name"])
if _, inGit := props["vcs.url"]; inGit {
assert.NotEmpty(t, props["vcs.revision"], "vcs.revision must accompany vcs.url")
}
}
// =============================== Multi-module (66-72) ==========================================
func TestDotnetFlexPackDistinctModulesForRestoreAndPush(t *testing.T) {
// Scenario #72 - a restore module and a push module recorded under the same build coexist as
// separate modules rather than overwriting each other.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
buildNumber := "27"
require.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln",
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
nupkgPath, _ := buildTestNupkg(t, "DotnetTwoModules", "1.0.0")
require.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo,
"--build-name="+tests.DotnetBuildName, "--build-number="+buildNumber))
defer deleteDotnetBuild()
published := publishAndGetDotnetBuildInfo(t, buildNumber)
assert.NotEmpty(t, allDeps(published), "restore module's dependencies must survive")
assert.NotEmpty(t, allArtifacts(published), "push module's artifacts must survive")
}
// ============================== Flag validation (80-81) ========================================
func TestDotnetFlexPackFlagPassthrough(t *testing.T) {
// Scenarios #80, #81 - native verbosity flags and the `--` separator are passed through to the
// dotnet CLI rather than being consumed by jf.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
t.Run("verbosity", func(t *testing.T) {
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln", "--verbosity", "quiet"))
})
// Scenario #81 - a user's "--" separator is respected. Everything after it is forwarded to
// MSBuild, so jf's injected --configfile has to be placed BEFORE the separator; appending it
// blindly used to send it to MSBuild's parser and fail the restore with:
//
// MSBUILD : error MSB1001: Unknown switch.
// Switch: --configfile
//
// Fixed by insertBeforeSeparator in jfrog-cli-artifactory's nuget command; this passes once
// go.mod resolves a version carrying it (jfrog-cli-artifactory PR #551).
t.Run("double-dash-separator", func(t *testing.T) {
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln", "--", "--verbosity", "minimal"))
})
}
// ============================= Repo & server errors (82-86) ====================================
func TestDotnetFlexPackRepoAndServerErrors(t *testing.T) {
// Scenarios #41, #82, #83 - a nonexistent resolve repository and an unknown server id must
// each produce a clear error rather than a silent success or an opaque native failure.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
cases := []struct {
name string
args []string
}{
{"nonexistent-repo", []string{dotnetUtils.DotnetCore.String(), "restore", "reference.sln",
"--repo-resolve=cli-dotnet-does-not-exist"}},
{"nonexistent-server", []string{dotnetUtils.DotnetCore.String(), "restore", "reference.sln",
"--repo-resolve=" + tests.NugetRemoteRepo, "--server-id=cli-dotnet-no-such-server"}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
args := tc.args
allowInsecureConnectionForFlexPackTests(&args)
assert.Error(t, runDotnetFlexPack(t, args...))
})
}
}
// ================================== Repo types (87-92) =========================================
func TestDotnetFlexPackResolveViaVirtualRepo(t *testing.T) {
// Scenario #90 - resolving through a virtual repo aggregating local + remote works, which is
// the V3 PackageBaseAddress path.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetVirtualRepo, "reference.sln"))
}
// ================================== Round-trip (93-95) =========================================
func TestDotnetFlexPackPushRestoreRoundTrip(t *testing.T) {
// Scenario #93 - a pushed package is resolvable again from the same repo.
initNugetTest(t)
defer cleanTestsHomeEnv()
nupkgPath, _ := buildTestNupkg(t, "DotnetRoundTrip", "1.2.3")
require.NoError(t, pushNupkgDotnetFlexPack(t, nupkgPath, tests.NugetLocalRepo))
props := getFlexPackItemProps(t, tests.NugetLocalRepo+"/"+filepath.Base(nupkgPath))
assert.NotNil(t, props, "pushed package must be retrievable from the repo it was pushed to")
}
// ============================ Native vs legacy syntax (113-118) ================================
func TestDotnetFlexPackRunNativeTogglesCodePath(t *testing.T) {
// Scenarios #115, #116, #117 - JFROG_RUN_NATIVE selects the code path. With the env var unset
// and no dotnet.yaml present, the legacy path must demand 'jf dotnet-config'; with it set,
// FlexPack runs statelessly. This is also the regression guard for the gate change that made
// JFROG_RUN_NATIVE win over a stale config file.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
t.Run("native-unset-uses-legacy", func(t *testing.T) {
err := runDotnetLegacy(t, dotnetUtils.DotnetCore.String(), "restore", "reference.sln")
assert.Error(t, err, "legacy path with no dotnet.yaml must ask for 'jf dotnet-config'")
})
t.Run("native-true-uses-flexpack", func(t *testing.T) {
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln"),
"FlexPack must run statelessly with no config file")
})
}
// ============================== Auth / credentials (145-159) ===================================
func TestDotnetFlexPackCredentialsNotWrittenToDisk(t *testing.T) {
// Scenarios #145, #150, #151, #156 - ASSERTED AS IMPLEMENTED, NOT AS SPECIFIED.
//
// The plan states JFrog CLI injects nothing and exports nothing to the child environment. The
// implementation writes a temp nuget.config declaring the Artifactory source and passes
// credentials through NuGetPackageSourceCredentials_<source>. The security property that
// matters - no secret written to disk - is what this pins: restore must succeed while the
// user's own config carries no credentials, and must not gain any afterwards.
initNugetTest(t)
defer cleanTestsHomeEnv()
projectPath, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
userConfig := filepath.Join(projectPath, "nuget.config")
require.NoError(t, os.WriteFile(userConfig, []byte(`<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
</packageSources>
</configuration>`), 0o600))
// Succeeds even though no credential exists anywhere the native client could read unaided.
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln"))
after, err := os.ReadFile(userConfig)
require.NoError(t, err)
assert.NotContains(t, string(after), "ClearTextPassword")
assert.NotContains(t, string(after), "packageSourceCredentials")
}
func TestDotnetFlexPackLeavesNoTempConfigBehind(t *testing.T) {
// Scenario #158 - the temp nuget.config is removed by a deferred cleanup, and concurrent
// invocations must not share one. Pin that a completed run leaves nothing behind.
initNugetTest(t)
defer cleanTestsHomeEnv()
_, cleanup := enterDotnetProject(t, "reference")
defer cleanup()
pattern := filepath.Join(os.TempDir(), "jfrog-nuget-*.config")
before, err := filepath.Glob(pattern)
require.NoError(t, err)
assert.NoError(t, restoreDotnetFlexPack(t, tests.NugetRemoteRepo, "reference.sln"))
after, err := filepath.Glob(pattern)
require.NoError(t, err)
assert.LessOrEqual(t, len(after), len(before), "temp nuget.config files were left behind: %v", after)
}
func TestDotnetFlexPackAnonymousRestoreNoInjection(t *testing.T) {
// Scenarios #153, #159 - with no --repo-resolve there is nothing to inject, so FlexPack must
// leave auth entirely to the user's own configuration and still run the native command.
initNugetTest(t)
defer cleanTestsHomeEnv()
projectPath, cleanup := enterDotnetProject(t, "reference")
defer cleanup()