{"id":13413904,"url":"https://github.com/madflojo/testcerts","last_synced_at":"2025-04-30T22:24:58.828Z","repository":{"id":57491592,"uuid":"196418447","full_name":"madflojo/testcerts","owner":"madflojo","description":"Dynamically generate self-signed certificates and certificate authorities for Go tests","archived":false,"fork":false,"pushed_at":"2024-05-19T21:17:06.000Z","size":78,"stargazers_count":45,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-20T16:14:05.880Z","etag":null,"topics":["certificate-generation","go","golang","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/madflojo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-11T15:15:15.000Z","updated_at":"2024-06-18T22:35:41.282Z","dependencies_parsed_at":"2023-02-15T23:45:20.553Z","dependency_job_id":"fff4cb18-cdfc-45fa-aa27-2104be225c34","html_url":"https://github.com/madflojo/testcerts","commit_stats":{"total_commits":22,"total_committers":4,"mean_commits":5.5,"dds":0.5,"last_synced_commit":"ad7679b95078daffca93ca6684eef727d7bda004"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madflojo%2Ftestcerts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madflojo%2Ftestcerts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madflojo%2Ftestcerts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madflojo%2Ftestcerts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/madflojo","download_url":"https://codeload.github.com/madflojo/testcerts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251790597,"owners_count":21644246,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["certificate-generation","go","golang","testing"],"created_at":"2024-07-30T20:01:52.424Z","updated_at":"2025-04-30T22:24:58.804Z","avatar_url":"https://github.com/madflojo.png","language":"Go","readme":"# testcerts\n\n![Actions Status](https://github.com/madflojo/testcerts/actions/workflows/go.yaml/badge.svg?branch=main)\n[![codecov](https://codecov.io/gh/madflojo/testcerts/branch/main/graph/badge.svg?token=H9C9B6I0AS)](https://codecov.io/gh/madflojo/testcerts)\n[![Go Report Card](https://goreportcard.com/badge/github.com/madflojo/testcerts)](https://goreportcard.com/report/github.com/madflojo/testcerts)\n[![Go Reference](https://pkg.go.dev/badge/github.com/madflojo/testcerts.svg)](https://pkg.go.dev/github.com/madflojo/testcerts)\n[![license](https://img.shields.io/github/license/madflojo/testcerts.svg?maxAge=2592000)](https://github.com/madflojo/testcerts/LICENSE)\n\nStop saving test certificates in your code repos. Start generating them in your tests.\n\n```go\nfunc TestFunc(t *testing.T) {\n\t// Create and write self-signed Certificate and Key to temporary files\n\tcert, key, err := testcerts.GenerateToTempFile(\"/tmp/\")\n\tif err != nil {\n\t\t// do something\n\t}\n\tdefer os.Remove(key)\n\tdefer os.Remove(cert)\n\n\t// Start HTTP Listener with test certificates\n\terr = http.ListenAndServeTLS(\"127.0.0.1:443\", cert, key, someHandler)\n\tif err != nil {\n\t\t// do something\n\t}\n}\n```\n\nFor more complex tests, you can also use this package to create a Certificate Authority and a key pair signed by that Certificate Authority for any test domain you want.\n\n```go\nfunc TestFunc(t *testing.T) {\n\t// Generate Certificate Authority\n\tca := testcerts.NewCA()\n\n\tgo func() {\n\t\t// Create a signed Certificate and Key for \"localhost\"\n\t\tcerts, err := ca.NewKeyPair(\"localhost\")\n\t\tif err != nil {\n\t\t\t// do something\n\t\t}\n\n\t\t// Write certificates to a file\n\t\terr = certs.ToFile(\"/tmp/cert\", \"/tmp/key\")\n\t\tif err {\n\t\t\t// do something\n\t\t}\n\n\t\t// Start HTTP Listener\n\t\terr = http.ListenAndServeTLS(\"localhost:443\", \"/tmp/cert\", \"/tmp/key\", someHandler)\n\t\tif err != nil {\n\t\t\t// do something\n\t\t}\n\t}()\n\n\t// Create a client with the self-signed CA\n\tclient := \u0026http.Client{\n\t\tTransport: \u0026http.Transport{\n\t\t\tTLSClientConfig: certs.ConfigureTLSConfig(ca.GenerateTLSConfig()),\n\t\t},\n\t}\n\n\t// Make an HTTPS request\n\tr, _ := client.Get(\"https://localhost\")\n}\n```\n\nSimplify your testing, and don't hassle with certificates anymore.\n\n## Contributing\n\nIf you find a bug or have an idea for a feature, please open an issue or a pull request.\n\n## License\n\ntestcerts is released under the MIT License. See [LICENSE](./LICENSE) for details.\n\n\n\n","funding_links":[],"categories":["Testing","测试","Template Engines"],"sub_categories":["Testing Frameworks"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadflojo%2Ftestcerts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadflojo%2Ftestcerts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadflojo%2Ftestcerts/lists"}