@@ -548,6 +548,40 @@ func TestSubmitRelativePath(t *testing.T) {
548
548
assert .Equal (t , "This is a file." , submittedFiles ["file.txt" ])
549
549
}
550
550
551
+ func TestExerciseDirnameMatchesMetadataSlug (t * testing.T ) {
552
+ submittedFiles := map [string ]string {}
553
+ ts := fakeSubmitServer (t , submittedFiles )
554
+ defer ts .Close ()
555
+
556
+ tmpDir , err := ioutil .TempDir ("" , "submit-files" )
557
+ defer os .RemoveAll (tmpDir )
558
+ assert .NoError (t , err )
559
+
560
+ dir := filepath .Join (tmpDir , "bogus-track" , "bogus-exercise-doesnt-match-metadata-slug" )
561
+ os .MkdirAll (filepath .Join (dir , "subdir" ), os .FileMode (0755 ))
562
+ writeFakeMetadata (t , dir , "bogus-track" , "bogus-exercise" )
563
+
564
+ file1 := filepath .Join (dir , "file-1.txt" )
565
+ err = ioutil .WriteFile (file1 , []byte ("This is file 1." ), os .FileMode (0755 ))
566
+ assert .NoError (t , err )
567
+
568
+ v := viper .New ()
569
+ v .Set ("token" , "abc123" )
570
+ v .Set ("workspace" , tmpDir )
571
+ v .Set ("apibaseurl" , ts .URL )
572
+
573
+ cfg := config.Config {
574
+ Persister : config.InMemoryPersister {},
575
+ Dir : tmpDir ,
576
+ UserViperConfig : v ,
577
+ }
578
+
579
+ err = runSubmit (cfg , pflag .NewFlagSet ("fake" , pflag .PanicOnError ), []string {file1 })
580
+ if assert .Error (t , err ) {
581
+ assert .Regexp (t , "directory does not match exercise slug" , err .Error ())
582
+ }
583
+ }
584
+
551
585
func writeFakeMetadata (t * testing.T , dir , trackID , exerciseSlug string ) {
552
586
metadata := & workspace.ExerciseMetadata {
553
587
ID : "bogus-solution-uuid" ,
0 commit comments