mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
63 lines
2.1 KiB
Go
63 lines
2.1 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package pwn
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type mockTransport struct{}
|
|
|
|
func (mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
if req.URL.Host != "api.pwnedpasswords.com" {
|
|
return nil, errors.New("unsupported host")
|
|
}
|
|
respMap := map[string]string{
|
|
"/range/5c1d8": "EAF2F254732680E8AC339B84F3266ECCBB5:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2",
|
|
"/range/ba189": "FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4",
|
|
"/range/a1733": "C4CE0F1F0062B27B9E2F41AF0C08218017C:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2\r\nFE81480327C992FE62065A827429DD1318B:0",
|
|
"/range/5617b": "FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0",
|
|
"/range/79082": "FDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0\r\nAFEF386F56EB0B4BE314E07696E5E6E6536:0",
|
|
}
|
|
if resp, ok := respMap[req.URL.Path]; ok {
|
|
return &http.Response{Request: req, Body: io.NopCloser(strings.NewReader(resp))}, nil
|
|
}
|
|
return nil, errors.New("unsupported path")
|
|
}
|
|
|
|
func TestPassword(t *testing.T) {
|
|
client := New(WithHTTP(&http.Client{Transport: mockTransport{}}))
|
|
|
|
count, err := client.CheckPassword("", false)
|
|
assert.ErrorIs(t, err, ErrEmptyPassword, "blank input should return ErrEmptyPassword")
|
|
assert.EqualValues(t, -1, count)
|
|
|
|
count, err = client.CheckPassword("pwned", false)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 1, count)
|
|
|
|
count, err = client.CheckPassword("notpwned", false)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 0, count)
|
|
|
|
count, err = client.CheckPassword("paddedpwned", true)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 1, count)
|
|
|
|
count, err = client.CheckPassword("paddednotpwned", true)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 0, count)
|
|
|
|
count, err = client.CheckPassword("paddednotpwnedzero", true)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 0, count)
|
|
}
|