Files
docconv/pdf_ocr_test.go
Jonathan Ingram 93312f47fc v2: initial commit (#153)
- Some methods have been changed to return an error as their last
  argument
- Log calls inside various functions have been removed
- Use a v1 tag if you need the previous signature
2023-10-31 11:32:40 +11:00

34 lines
703 B
Go

//go:build ocr
package docconv
import (
"os"
"testing"
)
func TestPDFHasImage_CannotExecuteCode(t *testing.T) {
// Try to inject code by passing a bad file path.
// If the code was successful it will create a file called foo in the working directory
badFilePath := "$(id >> foo).pdf"
got, err := PDFHasImage(badFilePath)
if err != nil {
t.Fatal(err)
}
if want := false; got != want {
t.Errorf("got %v, want %v", got, want)
}
if got, want := fileExists("foo"), false; got != want {
t.Errorf("got bad file exists, want not file to exist")
}
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}