<commit_before>// Copyright 2015 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========================================================================

package main

import (
	"bytes"
	"encoding/binary"
	"flag"
	"fmt"
	"io/ioutil"
	"os/exec"
	"path/filepath"
	"strings"
	"testing"
)

// Modified from the google3/googleclient/tools version so it can run outside of google3.
// Build certificate_tag separately, and point flag tag-binary-dir to the build location.
//
// Here is an example of testing the 32-bit version on Linux:
//
// $ GOARCH=386 CC=gcc go build -o /tmp/certificate_tag common/certificate_tag/certificate_tag.go
// $ GOARCH=386 CC=gcc go test common/certificate_tag/certificate_tag_test.go common/certificate_tag/certificate_tag.go
//
// Here is an example of testing the 32-bit version on Windows 10.
//
// $ go build -o C:/tmp/certificate_tag.exe common/certificate_tag/certificate_tag.go
// $ go test common/certificate_tag/certificate_tag_test.go common/certificate_tag/certificate_tag.go -tag-binary-dir "C:/tmp" -tag-binary-name "certificate_tag.exe"

var (
	tagBinaryDir  *string = flag.String("tag-binary-dir", "/tmp", "Path to directory with the tag binary.")
	tagBinaryName *string = flag.String("tag-binary-name", "certificate_tag", "Name of the tag binary file.")
	// tagBinary contains the path to the certificate_tag program.
	tagBinary string
	// sourceExe contains the path to a Chrome installer exe file.
	sourceExe string
	// sourceMSI* contains the path to a signed MSI file.
	sourceMSI1, sourceMSI2, sourceMSI3, sourceMSI4 string
)

// existingTagSubstring is a segment of the superfluous-cert tag that's already
// in ChromeSetup.exe.
const existingTagSubstring = ".....Gact.?omah"

func TestMain(m *testing.M) {
	flag.Parse()

	tagBinary = filepath.Join(*tagBinaryDir, *tagBinaryName)
	sourceExe = filepath.Join("testdata/ChromeSetup.exe")
	sourceMSI1 = filepath.Join("testdata/googlechromestandaloneenterprise.msi")
	sourceMSI2 = filepath.Join("testdata/test7zSigned.msi")
	sourceMSI3 = filepath.Join("testdata/OmahaTestSigned.msi")
	sourceMSI4 = filepath.Join("testdata/test7zSigned-smallcert.msi")

	m.Run()
}

func TestPrintAppendedTag(t *testing.T) {
	cmd := exec.Command(tagBinary, "--dump-appended-tag", sourceExe)
	output, err := cmd.CombinedOutput()<commit_msg>Remove binary name; windows can run a non-exe executable just fine<commit_after>// Copyright 2015 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========================================================================

package main

import (
	"bytes"
	"encoding/binary"
	"flag"
	"fmt"
	"io/ioutil"
	"os/exec"
	"path/filepath"
	"strings"
	"testing"
)

// Modified from the google3/googleclient/tools version so it can run outside of google3.
// Build certificate_tag separately, and point flag tag-binary-dir to the build location.
//
// Here is an example of testing the 32-bit version on Linux:
//
// $ GOARCH=386 CC=gcc go build -o /tmp/certificate_tag common/certificate_tag/certificate_tag.go
// $ GOARCH=386 CC=gcc go test common/certificate_tag/certificate_tag_test.go common/certificate_tag/certificate_tag.go
//
// Here is an example of testing the 32-bit version on Windows 10.
//
// $ go build -o C:/tmp/certificate_tag common/certificate_tag/certificate_tag.go
// $ go test common/certificate_tag/certificate_tag_test.go common/certificate_tag/certificate_tag.go -tag-binary-dir "C:/tmp"

var (
	tagBinaryDir *string = flag.String("tag-binary-dir", "/tmp", "Path to directory with the tag binary.")
	// tagBinary contains the path to the certificate_tag program.
	tagBinary string
	// sourceExe contains the path to a Chrome installer exe file.
	sourceExe string
	// sourceMSI* contains the path to a signed MSI file.
	sourceMSI1, sourceMSI2, sourceMSI3, sourceMSI4 string
)

// existingTagSubstring is a segment of the superfluous-cert tag that's already
// in ChromeSetup.exe.
const existingTagSubstring = ".....Gact.?omah"

func TestMain(m *testing.M) {
	flag.Parse()

	tagBinary = filepath.Join(*tagBinaryDir, "certificate_tag")
	sourceExe = filepath.Join("testdata/ChromeSetup.exe")
	sourceMSI1 = filepath.Join("testdata/googlechromestandaloneenterprise.msi")
	sourceMSI2 = filepath.Join("testdata/test7zSigned.msi")
	sourceMSI3 = filepath.Join("testdata/OmahaTestSigned.msi")
	sourceMSI4 = filepath.Join("testdata/test7zSigned-smallcert.msi")

	m.Run()
}

func TestPrintAppendedTag(t *testing.T) {
	cmd := exec.Command(tagBinary, "--dump-appended-tag", sourceExe)
	output, err := cmd.CombinedOutput()
{'fraction_non_alphanumeric': 0.1339781479491313, 'fraction_numerical': 0.011463370947519255, 'mean_word_length': 4.318095238095238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2485813', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1715, 'n_words': 533}