mirror of
https://github.com/sajari/docconv.git
synced 2026-10-16 21:21:59 +08:00
93312f47fc
- 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
34 lines
703 B
Go
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()
|
|
}
|