mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
81 lines
3.2 KiB
Go
81 lines
3.2 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
"time"
|
|
|
|
auth_model "github.com/hanzoai/git/models/auth"
|
|
api "github.com/hanzoai/git/modules/structs"
|
|
"github.com/hanzoai/git/modules/test"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var testLicenseContent = `
|
|
Copyright (c) 2024 Hanzo AI, Inc.
|
|
|
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
`
|
|
|
|
func TestAPIRepoLicense(t *testing.T) {
|
|
onGitRun(t, func(t *testing.T, u *url.URL) {
|
|
session := loginUser(t, "user2")
|
|
|
|
// Request editor page
|
|
req := NewRequest(t, "GET", "/user2/repo1/_new/master/")
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
doc := NewHTMLParser(t, resp.Body)
|
|
lastCommit := doc.GetInputValueByName("last_commit")
|
|
assert.NotEmpty(t, lastCommit)
|
|
|
|
// Save new file to master branch
|
|
req = NewRequestWithValues(t, "POST", "/user2/repo1/_new/master/", map[string]string{
|
|
"last_commit": lastCommit,
|
|
"tree_path": "LICENSE",
|
|
"content": testLicenseContent,
|
|
"commit_choice": "direct",
|
|
})
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
assert.NotEmpty(t, test.RedirectURL(resp))
|
|
|
|
// let the forge update repo license
|
|
time.Sleep(time.Second)
|
|
checkRepoLicense(t, "user2", "repo1", []string{"BSD-2-Clause"})
|
|
|
|
// Change default branch
|
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
|
branchName := "DefaultBranch"
|
|
req = NewRequestWithJSON(t, "PATCH", "/v1/repos/user2/repo1", api.EditRepoOption{
|
|
DefaultBranch: &branchName,
|
|
}).AddTokenAuth(token)
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
// let the forge update repo license
|
|
time.Sleep(time.Second)
|
|
checkRepoLicense(t, "user2", "repo1", []string{"MIT"})
|
|
})
|
|
}
|
|
|
|
func checkRepoLicense(t *testing.T, owner, repo string, expected []string) {
|
|
reqURL := fmt.Sprintf("/v1/repos/%s/%s/licenses", owner, repo)
|
|
req := NewRequest(t, "GET", reqURL)
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
licenses := DecodeJSON(t, resp, []string{})
|
|
|
|
assert.ElementsMatch(t, expected, licenses, 0)
|
|
}
|