-
Notifications
You must be signed in to change notification settings - Fork 12
Initial cert validation test #2582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benjaminleonard
wants to merge
9
commits into
main
Choose a base branch
from
tls-cert-soft-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a559fd8
Initial cert validation test
benjaminleonard 2ee5586
Bot commit: format with prettier
github-actions[bot] ab5e67f
Spacing tweak
benjaminleonard 83d130e
Merge branch 'tls-cert-soft-validation' of https://github.com/oxideco…
benjaminleonard 4a9899d
oop
benjaminleonard 53a6a9a
Wildcard and error improvements with tests
benjaminleonard 21287b4
More pattern matching tweaks
benjaminleonard b629cee
move dynamic import to avoid suspense/lazy thing
david-crespo 6f9bdda
Merge branch 'main' into tls-cert-soft-validation
benjaminleonard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { matchesDomain, parseCertificate } from './TlsCertsField' | ||
|
||
describe('matchesDomain', () => { | ||
it('matches wildcard subdomains', () => { | ||
expect(matchesDomain('*.example.com', 'sub.example.com')).toBe(true) | ||
expect(matchesDomain('*.example.com', 'example.com')).toBe(false) | ||
expect(matchesDomain('*', 'any.domain')).toBe(false) | ||
}) | ||
|
||
it('matches exact matches', () => { | ||
expect(matchesDomain('example.com', 'example.com')).toBe(true) | ||
expect(matchesDomain('example.com', 'www.example.com')).toBe(false) | ||
}) | ||
|
||
it('matches multiple subdomains', () => { | ||
expect(matchesDomain('*.example.com', 'sub.sub.example.com')).toBe(false) | ||
expect(matchesDomain('*.example.com', 'sub.sub.sub.example.com')).toBe(false) | ||
}) | ||
|
||
it('matches with case insensitivity', () => { | ||
expect(matchesDomain('EXAMPLE.COM', 'example.com')).toBe(true) | ||
expect(matchesDomain('example.com', 'EXAMPLE.COM')).toBe(true) | ||
}) | ||
|
||
it('does not match incorrect wildcards', () => { | ||
expect(matchesDomain('test.*', 'test.com')).toBe(false) | ||
expect(matchesDomain('test.*', 'test.net')).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('parseCertificate', () => { | ||
const validCert = `-----BEGIN CERTIFICATE-----\nMIIDbjCCAlagAwIBAgIUVF36cv2UevtKOGWP3GNV1h+TpScwDQYJKoZIhvcNAQEL\nBQAwGzEZMBcGA1UEAwwQdGVzdC5leGFtcGxlLmNvbTAeFw0yNDExMjcxNDE4MTha\nFw0yNTExMjcxNDE4MThaMBsxGTAXBgNVBAMMEHRlc3QuZXhhbXBsZS5jb20wggEi\nMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC0cBavU9cnrTY7CaOsHdfzr7e4\nmT7eRCGJa1jmuGeADGIs1IcMr/7jgiKS/1P69SehfqpFWXKAYn5OH+ickZfs55AB\nuyfh+KogmTkX6I40CnP9GohfgAaDVr119a2kdJNvinsCjNGfulMBYiw+sJBp4l/c\nzQRYMXaMk1ARKBgUuVZHZXnkWQKjp/GAQjVsUjl/dnBVeUuS4/0OVTLL8U6mGzdy\nf5s03bpBLOOJ9Owg1We5urYA6glCvvMh1VhBPsCnHFj6aYLnnWpJkVuJEKA+znEU\nU2n6T0bQorzVnn5ROtAn3ao4sGIVMbMeIaEvUt3zyVk+gtUvqSTPChFde6/LAgMB\nAAGjgakwgaYwHQYDVR0OBBYEFFzp73YRPxxu4bTQvmJy5rqHNXh7MB8GA1UdIwQY\nMBaAFFzp73YRPxxu4bTQvmJy5rqHNXh7MA8GA1UdEwEB/wQFMAMBAf8wUwYDVR0R\nBEwwSoIQdGVzdC5leGFtcGxlLmNvbYISKi50ZXN0LmV4YW1wbGUuY29tghEqLmRl\ndi5leGFtcGxlLmNvbYIJbG9jYWxob3N0hwR/AAABMA0GCSqGSIb3DQEBCwUAA4IB\nAQCstbMiTwHuSlwuUslV9SxewdxTtKAjNgUnCn1Jv7hs44wNTBqvMzDq2HB26wRR\nOnbt6gReOj9GdSRmJPNcgouaAGJWCXuaZPs34LgRJir6Z0FVcK7/O3SqfTOg3tJg\ngzg4xmtzXc7Im4VgvaLS5iXCOvUaKf/rXeYDa3r37EF+vyzcETt5bXwtU8BBFvVT\nJfPDla5lYv0h9Z+XsYEAqtbChdy+fVuHnF+EygZCT9KVFBPWQrsaF1Qc/CvP/+LM\nCrdLoB+2pkWbX075tv8LIbL2dW5Gzyw+lU6lzPL9Vikm3QXGRklKHA4SVuZ3F9tr\nwPRLWb4aPmo1COkgvg3Moqdw\n-----END CERTIFICATE-----` | ||
|
||
const invalidCert = 'not-a-certificate' | ||
|
||
it('parses valid certificate', async () => { | ||
const result = await parseCertificate(validCert) | ||
expect(result).toEqual({ | ||
commonName: ['test.example.com'], | ||
subjectAltNames: [ | ||
'test.example.com', | ||
'*.test.example.com', | ||
'*.dev.example.com', | ||
'localhost', | ||
'127.0.0.1', | ||
], | ||
isValid: true, | ||
}) | ||
}) | ||
|
||
it('returns invalid for invalid certificate', async () => { | ||
const result = await parseCertificate(invalidCert) | ||
expect(result).toEqual({ | ||
commonName: [], | ||
subjectAltNames: [], | ||
isValid: false, | ||
}) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charliepark pointed out we might want to set the stale time directly here. I'm going to experiment with that and also maybe tweaking the query key.