chore: preserve paused QBit work and document remaining issues
QRun-IO/ci-policy: ci / fork-guard (push) Skipped
QRun-IO/ci-policy: ci / head-profile (push) Skipped
QRun-IO/ci-policy: ci / application-template-0 (push) Skipped
QRun-IO/ci-policy: ci / gradle-1 (push) Skipped
QRun-IO/ci-policy: ci / java-docker-3 (push) Skipped
QRun-IO/ci-policy: ci / java-docker-4 (push) Skipped
QRun-IO/ci-policy: ci / java-frontend-browser-5 (push) Skipped
QRun-IO/ci-policy: ci / java-maven-6 (push) Skipped
QRun-IO/ci-policy: ci / java-maven-7 (push) Skipped
QRun-IO/ci-policy: ci / node-8 (push) Skipped
QRun-IO/ci-policy: ci / node-9 (push) Skipped
QRun-IO/ci-policy: ci / node-10 (push) Skipped
QRun-IO/ci-policy: ci / node-playwright-11 (push) Skipped
QRun-IO/ci-policy: ci / repository-policy-12 (push) Skipped
QRun-IO/ci-policy: ci / source-config-13 (push) Skipped
QRun-IO/ci-policy: ci / source-config-14 (push) Skipped
QRun-IO/ci-policy: ci / android-0 (push) Skipped
QRun-IO/ci-policy: ci / original-business (push) Skipped
QRun-IO/ci-policy: ci / original-mcp (push) Skipped
QRun-IO/ci-policy: ci / original-voyage (push) Skipped
QRun-IO/ci-policy: ci / original-cli (push) Skipped
QRun-IO/ci-policy: ci / repository-policy (push) Skipped
QRun-IO/ci-policy: ci / java-core-2-head (push) Skipped
QRun-IO/ci-policy: ci / java-docker-3-head (push) Skipped
QRun-IO/ci-policy: ci / java-maven-6-head (push) Skipped
QRun-IO/ci-policy: ci / java-maven-7-head (push) Skipped
QRun-IO/ci-policy: ci / not-enrolled (push) Failing after 7s
QRun-IO/ci-policy: native / fork-deny (push) Skipped
QRun-IO/ci-policy: native / dotnet-0 (push) Skipped
QRun-IO/ci-policy: ci / ci-result (push) Failing after 6s
QRun-IO/ci-policy: native / native-result (push) Successful in 6s
QRun-IO/ci-policy: ci / fork-guard (push) Skipped
QRun-IO/ci-policy: ci / head-profile (push) Skipped
QRun-IO/ci-policy: ci / application-template-0 (push) Skipped
QRun-IO/ci-policy: ci / gradle-1 (push) Skipped
QRun-IO/ci-policy: ci / java-docker-3 (push) Skipped
QRun-IO/ci-policy: ci / java-docker-4 (push) Skipped
QRun-IO/ci-policy: ci / java-frontend-browser-5 (push) Skipped
QRun-IO/ci-policy: ci / java-maven-6 (push) Skipped
QRun-IO/ci-policy: ci / java-maven-7 (push) Skipped
QRun-IO/ci-policy: ci / node-8 (push) Skipped
QRun-IO/ci-policy: ci / node-9 (push) Skipped
QRun-IO/ci-policy: ci / node-10 (push) Skipped
QRun-IO/ci-policy: ci / node-playwright-11 (push) Skipped
QRun-IO/ci-policy: ci / repository-policy-12 (push) Skipped
QRun-IO/ci-policy: ci / source-config-13 (push) Skipped
QRun-IO/ci-policy: ci / source-config-14 (push) Skipped
QRun-IO/ci-policy: ci / android-0 (push) Skipped
QRun-IO/ci-policy: ci / original-business (push) Skipped
QRun-IO/ci-policy: ci / original-mcp (push) Skipped
QRun-IO/ci-policy: ci / original-voyage (push) Skipped
QRun-IO/ci-policy: ci / original-cli (push) Skipped
QRun-IO/ci-policy: ci / repository-policy (push) Skipped
QRun-IO/ci-policy: ci / java-core-2-head (push) Skipped
QRun-IO/ci-policy: ci / java-docker-3-head (push) Skipped
QRun-IO/ci-policy: ci / java-maven-6-head (push) Skipped
QRun-IO/ci-policy: ci / java-maven-7-head (push) Skipped
QRun-IO/ci-policy: ci / not-enrolled (push) Failing after 7s
QRun-IO/ci-policy: native / fork-deny (push) Skipped
QRun-IO/ci-policy: native / dotnet-0 (push) Skipped
QRun-IO/ci-policy: ci / ci-result (push) Failing after 6s
QRun-IO/ci-policy: native / native-result (push) Successful in 6s
Save the current implementation and README, status, and known-issue documentation at the user-requested stop. No completed release or deployment is claimed. Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: GPT-6 Codex <noreply@openai.com>
This commit is contained in:
257 files changed
+47918
No files matched your search
+191
@@ -0,0 +1,191 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to the Licensor for inclusion in the Work by the copyright
|
||||
owner or by an individual or Legal Entity authorized to submit on
|
||||
behalf of the copyright owner. For the purposes of this definition,
|
||||
"submitted" means any form of electronic, verbal, or written
|
||||
communication sent to the Licensor or its representatives, including
|
||||
but not limited to communication on electronic mailing lists, source
|
||||
code control systems, and issue tracking systems that are managed by,
|
||||
or on behalf of, the Licensor for the purpose of discussing and
|
||||
improving the Work, but excluding communication that is conspicuously
|
||||
marked or otherwise designated in writing by the copyright owner as
|
||||
"Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2024 Kingsrook, LLC
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,6 @@
|
||||
QBit Scripting
|
||||
Copyright 2026 Kingsrook, LLC
|
||||
|
||||
This product includes software developed at Kingsrook, LLC (https://kingsrook.com/).
|
||||
|
||||
Licensed under the Apache License, Version 2.0.
|
||||
@@ -0,0 +1,33 @@
|
||||
# GitHub source importer
|
||||
|
||||
Optional `com.kingsrook.qbits:qbit-scripting-github:0.1.0-SNAPSHOT` adapter implements the base QBit's `GitSourceImporter` port. It has no dependency on another QBit's credential registry, UI or runtime. Install it explicitly with `runtime.withImporter(new GitHubSourceImporter(hostManagedGitHubAccess))`.
|
||||
|
||||
`GitHubAccess.tokenFor(Actor, scriptId, repository)` must authorize the current actor, project and exact repository on every call, and obtain a read-only short-lived credential from the host's existing managed credential provider. Throw to deny. A null result means the host explicitly authorized anonymous public access. This is not automatic anonymous fallback. Credential text is used only in the trusted Authorization header and is never persisted, logged, returned to a browser or passed to a worker. No new OAuth application, token store or environment-token guessing is implemented.
|
||||
|
||||
Imports require a full lowercase 40-character commit SHA. The adapter uses GitHub.com's fixed HTTPS API host, never follows redirects or response-provided URLs, checks returned commit/tree identities, rejects truncated trees, verifies every blob's Git SHA-1 and declared size, and decodes strict UTF-8. It uses the documented [Git commit](https://docs.github.com/en/rest/git/commits), [tree](https://docs.github.com/en/rest/git/trees) and [blob](https://docs.github.com/en/rest/git/blobs) response shapes. Transport trust is GitHub HTTPS; the adapter does not claim verification of a commit author's cryptographic signature.
|
||||
|
||||
The selected directory must contain ordinary non-executable `.ts` files and directories only. Symlinks, submodules, archives, manifests, JavaScript, unsupported paths and duplicate case-insensitive paths fail the whole import. Use a dedicated source directory in repositories containing README files or package manifests. No clone, checkout, package installation, build hooks or CI scripts run. Branches and tags are not accepted. Import/sync is an explicit action against an exact new commit; there is no automatic webhook or background fetch.
|
||||
|
||||
Bounds: 45-second whole import deadline, at most 15 seconds per HTTP request including body delivery, 1 MiB per encoded response, 1,000 tree entries, 200 source files, 256 KiB per file and 2 MiB decoded source total. Oversized streaming responses cancel before JSON allocation. Hosts still need normal request admission/rate limits. Current repository authorization is reevaluated before each HTTP request; current draft permission and project authorization are reevaluated after network work and before the database transaction commits.
|
||||
|
||||
The service writes a core source revision/files and `scripting_import` receipt in one transaction. The receipt stores repository, commit, selected directory, canonical SHA-256, current actor and timestamp. It is provenance, not another byte registry. Use the matching owner schema/migrations for the explicitly qualified H2 or MySQL deployment; archived PostgreSQL SQL is not production backend qualification. A JDBC test proves receipt failure rolls back every source row. An import never compiles, tests, publishes or binds automatically.
|
||||
|
||||
From the base directory: `./mvnw -f github/pom.xml verify`. Seven trusted HTTP-response/stream tests pass, including mode/path denial, truncation, tampered blob data, repository denial and subtree selection. No private repository or real external HTTP request was used in tests. Host credential integration and production GitHub transport qualification remain deployment work. The existing semantic UI/UX API and Next editor expose this import through the reviewed core isolation authority.
|
||||
|
||||
## Native process clients
|
||||
|
||||
The producer registers `scripting_import_commit` on a selected Script record. Its ordinary
|
||||
EDIT_FORM asks for `owner/repository`, the full lowercase 40-character commit SHA and an optional
|
||||
TypeScript-only subdirectory. No token, provider URL or actor field is accepted. With no configured
|
||||
importer preparation refuses; repository access still belongs to the host-managed `GitHubAccess`.
|
||||
|
||||
The server retains the expected current revision between prepare and apply. Submit delegates to
|
||||
the same `ScriptingService.importDraft` used by the semantic API and editor. Stale source, revoked
|
||||
authoring permission and narrowed credential/channel write ceilings refuse before retrieval;
|
||||
authority and optimistic revision are checked again in the final transaction. Import creates a
|
||||
new immutable full draft file set and receipt, preserving prior revisions. The result links that
|
||||
revision and displays its repository/commit/directory/source hash. Check, test and publish remain
|
||||
separate actions. CLI, TUI and other QQQ process clients need no Next-specific import workflow.
|
||||
|
||||
Native process tests use a trusted source importer fixture with actual owner persistence and
|
||||
metadata. They do not contact GitHub or establish production credential/transport qualification.
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent><groupId>com.kingsrook</groupId><artifactId>qbit-build-parent</artifactId><version>2.0.0</version><relativePath/></parent>
|
||||
<groupId>com.kingsrook.qbits</groupId><artifactId>qbit-scripting-github</artifactId><version>${revision}</version>
|
||||
<properties><revision>0.1.0-SNAPSHOT</revision><maven.compiler.release>21</maven.compiler.release><maven.compiler.proc>none</maven.compiler.proc><qqq.version>4.1.0-RC.21</qqq.version><qqq.core.version>4.1.0-RC.21</qqq.core.version></properties>
|
||||
<dependencyManagement><dependencies>
|
||||
<dependency><groupId>com.kingsrook.qqq</groupId><artifactId>qqq-backend-core</artifactId><version>${qqq.core.version}</version></dependency>
|
||||
<dependency><groupId>com.kingsrook.qqq</groupId><artifactId>qqq-backend-module-rdbms</artifactId><version>${qqq.core.version}</version></dependency>
|
||||
<dependency><groupId>com.kingsrook.qqq</groupId><artifactId>qqq-bom-pom</artifactId><version>${qqq.version}</version><type>pom</type><scope>import</scope></dependency>
|
||||
<dependency><groupId>org.junit</groupId><artifactId>junit-bom</artifactId><version>6.0.1</version><type>pom</type><scope>import</scope></dependency>
|
||||
</dependencies></dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency><groupId>com.kingsrook.qbits</groupId><artifactId>qbit-scripting</artifactId><version>${revision}</version></dependency>
|
||||
<dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>6.0.1</version><scope>test</scope></dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
<resource><directory>src/main/resources</directory><filtering>false</filtering></resource>
|
||||
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>3.3.1</version>
|
||||
<executions><execution><id>package-license-notices</id><phase>process-resources</phase><goals><goal>copy-resources</goal></goals>
|
||||
<configuration><outputDirectory>${project.build.outputDirectory}/META-INF</outputDirectory><resources><resource>
|
||||
<directory>${project.basedir}</directory><filtering>false</filtering><includes><include>LICENSE</include><include>NOTICE</include></includes>
|
||||
</resource></resources></configuration>
|
||||
</execution></executions>
|
||||
</plugin>
|
||||
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.14.1</version></plugin>
|
||||
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>3.5.4</version></plugin>
|
||||
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-checkstyle-plugin</artifactId><version>3.3.1</version>
|
||||
<dependencies><dependency><groupId>com.puppycrawl.tools</groupId><artifactId>checkstyle</artifactId><version>10.12.6</version></dependency></dependencies>
|
||||
<configuration><configLocation>${project.basedir}/../checkstyle/config.xml</configLocation><propertyExpansion>checkstyle.reactor.root=${maven.multiModuleProjectDirectory}</propertyExpansion><includeTestSourceDirectory>true</includeTestSourceDirectory><consoleOutput>true</consoleOutput><violationSeverity>warning</violationSeverity><failOnViolation>true</failOnViolation></configuration>
|
||||
<executions><execution><phase>validate</phase><goals><goal>check</goal></goals></execution></executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- Publish a self-contained POM: ${revision}/property versions are resolved at build time, so a consumer needs no -Drevision -->
|
||||
<groupId>org.codehaus.mojo</groupId><artifactId>flatten-maven-plugin</artifactId><version>1.7.3</version>
|
||||
<configuration><updatePomFile>true</updatePomFile><flattenMode>ossrh</flattenMode></configuration>
|
||||
<executions>
|
||||
<execution><id>flatten</id><phase>process-resources</phase><goals><goal>flatten</goal></goals></execution>
|
||||
<execution><id>flatten.clean</id><phase>clean</phase><goals><goal>clean</goal></goals></execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins></build>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 com.kingsrook.qbits.scripting.github;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.Flow;
|
||||
|
||||
/*******************************************************************************
|
||||
** Enforce body size while HTTP bytes arrive, before JSON allocation.
|
||||
*******************************************************************************/
|
||||
final class BoundedBody implements HttpResponse.BodySubscriber<byte[]>
|
||||
{
|
||||
private final int maximum;
|
||||
private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
private final CompletableFuture<byte[]> result = new CompletableFuture<>();
|
||||
private Flow.Subscription subscription;
|
||||
|
||||
/***************************************************************************
|
||||
** Per-request maximum includes encoded JSON overhead.
|
||||
***************************************************************************/
|
||||
BoundedBody(int maximum)
|
||||
{
|
||||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** The HTTP future completes only after bounded body delivery.
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public CompletionStage<byte[]> getBody()
|
||||
{
|
||||
return (result);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Pull one chunk at a time to bound outstanding input.
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public void onSubscribe(Flow.Subscription value)
|
||||
{
|
||||
subscription = value;
|
||||
value.request(1);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Reject oversized content without retaining the remaining body.
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public void onNext(List<ByteBuffer> chunks)
|
||||
{
|
||||
for(ByteBuffer chunk : chunks)
|
||||
{
|
||||
if(chunk.remaining() > maximum - bytes.size())
|
||||
{
|
||||
subscription.cancel();
|
||||
result.completeExceptionally(new IllegalArgumentException("GitHub response exceeds limit"));
|
||||
return;
|
||||
}
|
||||
byte[] value = new byte[chunk.remaining()];
|
||||
chunk.get(value);
|
||||
bytes.writeBytes(value);
|
||||
}
|
||||
subscription.request(1);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Propagate transport failure without logging its details.
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public void onError(Throwable error)
|
||||
{
|
||||
result.completeExceptionally(error);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Final immutable response bytes.
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public void onComplete()
|
||||
{
|
||||
result.complete(bytes.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 com.kingsrook.qbits.scripting.github;
|
||||
|
||||
import com.kingsrook.qbits.scripting.ScriptingException;
|
||||
import com.kingsrook.qbits.scripting.service.Actor;
|
||||
|
||||
/*******************************************************************************
|
||||
** Host-managed repository authorization and credential lookup. Implementations
|
||||
** authorize the current actor/project/repository on EVERY call; deny by throwing.
|
||||
** Return null only for explicitly authorized anonymous public access. Tokens
|
||||
** stay in trusted HTTP requests, never source records, contexts or diagnostics.
|
||||
*******************************************************************************/
|
||||
@FunctionalInterface
|
||||
public interface GitHubAccess
|
||||
{
|
||||
/***************************************************************************
|
||||
** Resolve a short-lived read-only credential from the host's existing store.
|
||||
***************************************************************************/
|
||||
String tokenFor(Actor actor, Integer scriptId, String repository) throws ScriptingException;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 com.kingsrook.qbits.scripting.github;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.CodingErrorAction;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import com.kingsrook.qbits.scripting.ScriptingException;
|
||||
import com.kingsrook.qbits.scripting.service.Actor;
|
||||
import com.kingsrook.qbits.scripting.source.GitCommitRef;
|
||||
import com.kingsrook.qbits.scripting.source.GitSourceImporter;
|
||||
import com.kingsrook.qbits.scripting.source.SourceFile;
|
||||
import com.kingsrook.qbits.scripting.source.SourceSnapshot;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/*******************************************************************************
|
||||
** Explicit GitHub.com exact-commit import. No clone, archives, redirects,
|
||||
** moving refs, URLs from responses, package installation or repository hooks.
|
||||
** Selected subtree must contain only ordinary UTF-8 .ts files and directories.
|
||||
*******************************************************************************/
|
||||
public final class GitHubSourceImporter implements GitSourceImporter
|
||||
{
|
||||
private static final int MAX_RESPONSE = 1024 * 1024;
|
||||
private static final int MAX_TREE_ENTRIES = 1000;
|
||||
private final GitHubAccess access;
|
||||
private final Reader reader;
|
||||
|
||||
/***************************************************************************
|
||||
** Trusted fixture seam; production requests always use the fixed GitHub host.
|
||||
***************************************************************************/
|
||||
@FunctionalInterface
|
||||
interface Reader
|
||||
{
|
||||
/***********************************************************************
|
||||
** Read one bounded response within the remaining operation deadline.
|
||||
***********************************************************************/
|
||||
byte[] get(String path, String token, int maximum, Duration timeout) throws Exception;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Host must explicitly install its existing repository authorization policy.
|
||||
***************************************************************************/
|
||||
public GitHubSourceImporter(GitHubAccess access)
|
||||
{
|
||||
this(access, GitHubSourceImporter::read);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Package-private deterministic HTTP-response fixtures, never a browser input.
|
||||
***************************************************************************/
|
||||
GitHubSourceImporter(GitHubAccess access, Reader reader)
|
||||
{
|
||||
this.access = Objects.requireNonNull(access);
|
||||
this.reader = Objects.requireNonNull(reader);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Verify exact commit identity, selected tree, blob size/hash and source policy.
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public SourceSnapshot importSnapshot(Actor actor, Integer scriptId, GitCommitRef ref) throws ScriptingException
|
||||
{
|
||||
Actor.requireCurrentIdentity(actor.id());
|
||||
long deadline = System.nanoTime() + Duration.ofSeconds(45).toNanos();
|
||||
String base = "/repos/" + ref.repository() + "/git/";
|
||||
try
|
||||
{
|
||||
JSONObject commit = get(actor, scriptId, ref, base + "commits/" + ref.commitSha(), deadline);
|
||||
require(ref.commitSha().equals(commit.getString("sha")), "Commit identity mismatch");
|
||||
String tree = sha(commit.getJSONObject("tree").getString("sha"));
|
||||
if(ref.subdirectory() != null)
|
||||
{
|
||||
for(String segment : ref.subdirectory().split("/"))
|
||||
{
|
||||
JSONArray entries = tree(actor, scriptId, ref, base, tree, false, deadline);
|
||||
String next = null;
|
||||
for(int i = 0; i < entries.length(); i++)
|
||||
{
|
||||
JSONObject entry = entries.getJSONObject(i);
|
||||
if(segment.equals(entry.getString("path")))
|
||||
{
|
||||
require(next == null && "tree".equals(entry.getString("type")) && "040000".equals(entry.getString("mode")), "Subdirectory must be an ordinary tree");
|
||||
next = sha(entry.getString("sha"));
|
||||
}
|
||||
}
|
||||
require(next != null, "Selected source directory is missing");
|
||||
tree = next;
|
||||
}
|
||||
}
|
||||
JSONArray entries = tree(actor, scriptId, ref, base, tree, true, deadline);
|
||||
List<JSONObject> blobs = new ArrayList<>();
|
||||
Set<String> paths = new HashSet<>();
|
||||
long total = 0;
|
||||
for(int i = 0; i < entries.length(); i++)
|
||||
{
|
||||
JSONObject entry = entries.getJSONObject(i);
|
||||
String path = entry.getString("path");
|
||||
require(paths.add(path.toLowerCase(java.util.Locale.ROOT)), "Duplicate source tree path");
|
||||
String type = entry.getString("type");
|
||||
String mode = entry.getString("mode");
|
||||
sha(entry.getString("sha"));
|
||||
if("tree".equals(type) && "040000".equals(mode))
|
||||
{
|
||||
SourceFile.validatePath(path + "/placeholder.ts");
|
||||
continue;
|
||||
}
|
||||
require("blob".equals(type) && "100644".equals(mode), "Only ordinary non-executable source files are accepted");
|
||||
SourceFile.validatePath(path);
|
||||
long size = size(entry);
|
||||
require(size <= SourceFile.MAX_CONTENT_BYTES, "Source file exceeds limit");
|
||||
total += size;
|
||||
require(total <= SourceSnapshot.MAX_TOTAL_BYTES && blobs.size() < SourceSnapshot.MAX_FILES, "Source snapshot exceeds limit");
|
||||
blobs.add(entry);
|
||||
}
|
||||
List<SourceFile> files = new ArrayList<>();
|
||||
for(JSONObject entry : blobs)
|
||||
{
|
||||
String expected = entry.getString("sha");
|
||||
JSONObject blob = get(actor, scriptId, ref, base + "blobs/" + expected, deadline);
|
||||
require(expected.equals(blob.getString("sha")) && "base64".equals(blob.getString("encoding")), "Invalid blob identity or encoding");
|
||||
byte[] bytes = Base64.getDecoder().decode(blob.getString("content").replace("\n", "").replace("\r", ""));
|
||||
require(bytes.length == size(entry) && bytes.length == size(blob), "Blob length mismatch");
|
||||
MessageDigest hash = MessageDigest.getInstance("SHA-1");
|
||||
hash.update(("blob " + bytes.length + "\0").getBytes(StandardCharsets.US_ASCII));
|
||||
require(expected.equals(SourceSnapshot.hex(hash.digest(bytes))), "Blob content hash mismatch");
|
||||
files.add(new SourceFile(entry.getString("path"), utf8(bytes)));
|
||||
}
|
||||
return (SourceSnapshot.of(ref.origin(), files));
|
||||
}
|
||||
catch(ScriptingException error)
|
||||
{
|
||||
throw error;
|
||||
}
|
||||
catch(Exception error)
|
||||
{
|
||||
throw new ScriptingException(ScriptingException.Kind.INVALID, "Repository response violates the source import policy");
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Reject partial trees; truncation must never silently drop source files.
|
||||
***************************************************************************/
|
||||
private JSONArray tree(Actor actor, Integer project, GitCommitRef ref, String base, String sha, boolean recursive, long deadline) throws ScriptingException
|
||||
{
|
||||
JSONObject response = get(actor, project, ref, base + "trees/" + sha + (recursive ? "?recursive=1" : ""), deadline);
|
||||
require(sha.equals(response.getString("sha")) && Boolean.FALSE.equals(response.get("truncated")), "Incomplete or mismatched source tree");
|
||||
JSONArray entries = response.getJSONArray("tree");
|
||||
require(entries.length() <= MAX_TREE_ENTRIES, "Tree entry count exceeds limit");
|
||||
return (entries);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Each request reauthorizes current actor/repository; no response URL is used.
|
||||
***************************************************************************/
|
||||
private JSONObject get(Actor actor, Integer project, GitCommitRef ref, String path, long deadline) throws ScriptingException
|
||||
{
|
||||
Actor.requireCurrentIdentity(actor.id());
|
||||
String token = access.tokenFor(actor, project, ref.repository());
|
||||
long remaining = deadline - System.nanoTime();
|
||||
if(remaining <= 0)
|
||||
{
|
||||
throw new ScriptingException(ScriptingException.Kind.UNAVAILABLE, "Source import deadline exceeded");
|
||||
}
|
||||
try
|
||||
{
|
||||
byte[] bytes = reader.get(path, token, MAX_RESPONSE, Duration.ofNanos(Math.min(remaining, Duration.ofSeconds(15).toNanos())));
|
||||
require(bytes.length <= MAX_RESPONSE, "Repository response exceeds limit");
|
||||
return (new JSONObject(utf8(bytes)));
|
||||
}
|
||||
catch(ScriptingException error)
|
||||
{
|
||||
throw error;
|
||||
}
|
||||
catch(Exception error)
|
||||
{
|
||||
if(error instanceof InterruptedException)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
throw new ScriptingException(ScriptingException.Kind.UNAVAILABLE, "Repository content is unavailable");
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Fixed public API host; managed credentials cannot follow redirects elsewhere.
|
||||
***************************************************************************/
|
||||
private static byte[] read(String path, String token, int maximum, Duration timeout) throws Exception
|
||||
{
|
||||
try(HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NEVER).connectTimeout(Duration.ofSeconds(5)).build())
|
||||
{
|
||||
var request = HttpRequest.newBuilder(URI.create("https://api.github.com" + path)).timeout(timeout)
|
||||
.header("Accept", "application/vnd.github+json").header("X-GitHub-Api-Version", "2026-03-10")
|
||||
.header("User-Agent", "QQQ-Scripting").GET();
|
||||
if(token != null)
|
||||
{
|
||||
request.header("Authorization", "Bearer " + token);
|
||||
}
|
||||
var future = client.sendAsync(request.build(), info -> new BoundedBody(maximum));
|
||||
try
|
||||
{
|
||||
var response = future.get(timeout.toMillis(), TimeUnit.MILLISECONDS);
|
||||
require(response.statusCode() == 200, "Repository request refused");
|
||||
return (response.body());
|
||||
}
|
||||
finally
|
||||
{
|
||||
future.cancel(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Numeric byte counts cannot be coerced from strings or fractional JSON.
|
||||
***************************************************************************/
|
||||
private static long size(JSONObject value) throws ScriptingException
|
||||
{
|
||||
Object size = value.get("size");
|
||||
require(size instanceof Integer || size instanceof Long, "Invalid blob size");
|
||||
long result = ((Number) size).longValue();
|
||||
require(result >= 0 && result <= SourceFile.MAX_CONTENT_BYTES, "Blob size exceeds limit");
|
||||
return (result);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** API object names are full immutable SHA-1 identifiers, never paths or refs.
|
||||
***************************************************************************/
|
||||
private static String sha(String value) throws ScriptingException
|
||||
{
|
||||
require(value.matches("[0-9a-f]{40}"), "Invalid Git object identity");
|
||||
return (value);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Reject malformed UTF-8 instead of changing source bytes during decoding.
|
||||
***************************************************************************/
|
||||
private static String utf8(byte[] bytes) throws Exception
|
||||
{
|
||||
return (StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
|
||||
.onUnmappableCharacter(CodingErrorAction.REPORT).decode(ByteBuffer.wrap(bytes)).toString());
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Fail the complete import; never return a filtered partial source snapshot.
|
||||
***************************************************************************/
|
||||
private static void require(boolean condition, String message) throws ScriptingException
|
||||
{
|
||||
if(!condition)
|
||||
{
|
||||
throw new ScriptingException(ScriptingException.Kind.INVALID, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 com.kingsrook.qbits.scripting.github;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Flow;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import com.kingsrook.qbits.scripting.ScriptingException;
|
||||
import com.kingsrook.qbits.scripting.service.Actor;
|
||||
import com.kingsrook.qbits.scripting.source.GitCommitRef;
|
||||
import com.kingsrook.qbits.scripting.source.SourceSnapshot;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QUser;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/*******************************************************************************
|
||||
** Trusted GitHub HTTP response fixtures. No repository is fetched or executed.
|
||||
*******************************************************************************/
|
||||
class GitHubSourceImporterTest
|
||||
{
|
||||
/***************************************************************************
|
||||
** Establish an identified local fixture session without repository access.
|
||||
***************************************************************************/
|
||||
@BeforeEach
|
||||
void setup()
|
||||
{
|
||||
QContext.init(null, new QSession().withUser(new QUser().withIdReference("author")));
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Drop fixture identity after each test.
|
||||
***************************************************************************/
|
||||
@AfterEach
|
||||
void cleanup()
|
||||
{
|
||||
QContext.clear();
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Actor is always derived from the actual current fixture session.
|
||||
***************************************************************************/
|
||||
private Actor everything() throws ScriptingException
|
||||
{
|
||||
return (Actor.fromSession(QContext.getQSession()));
|
||||
}
|
||||
|
||||
private static final String COMMIT = "a".repeat(40);
|
||||
private static final String TREE = "b".repeat(40);
|
||||
private static final GitCommitRef REF = new GitCommitRef("acme/scripts", COMMIT, null);
|
||||
|
||||
/***************************************************************************
|
||||
** Exact commit/tree/blob provenance, canonical files and per-request access.
|
||||
***************************************************************************/
|
||||
@Test
|
||||
void importsPinnedSourceWithCurrentRepositoryAuthorization() throws Exception
|
||||
{
|
||||
Map<String, JSONObject> responses = fixture("export const value = 1;");
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
var importer = importer(responses, calls);
|
||||
var first = importer.importSnapshot(everything(), 42, REF);
|
||||
var second = importer.importSnapshot(everything(), 42, REF);
|
||||
assertEquals(first.sha256(), second.sha256());
|
||||
assertEquals(REF.origin(), first.origin());
|
||||
assertEquals("src/main.ts", first.files().getFirst().path());
|
||||
assertTrue(first.verify());
|
||||
assertEquals(6, calls.get());
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Unknown files, executable files, symlinks and submodules are all refused.
|
||||
***************************************************************************/
|
||||
@Test
|
||||
void refusesUnsafeTreeEntriesBeforeFetchingAnyBlob() throws Exception
|
||||
{
|
||||
for(String mode : List.of("100755", "120000", "160000"))
|
||||
{
|
||||
var fixture = fixture("source");
|
||||
fixture.get("trees/" + TREE + "?recursive=1").getJSONArray("tree").getJSONObject(0).put("mode", mode);
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
assertThrows(ScriptingException.class, () -> importer(fixture, calls).importSnapshot(everything(), 42, REF));
|
||||
assertEquals(2, calls.get());
|
||||
}
|
||||
for(String path : List.of("package.json", "../main.ts", "/main.ts", "src\\main.ts", "file.zip"))
|
||||
{
|
||||
var fixture = fixture("source");
|
||||
fixture.get("trees/" + TREE + "?recursive=1").getJSONArray("tree").getJSONObject(0).put("path", path);
|
||||
assertThrows(ScriptingException.class, () -> importer(fixture, new AtomicInteger()).importSnapshot(everything(), 42, REF));
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Missing immutable identity or partial trees cannot become usable snapshots.
|
||||
***************************************************************************/
|
||||
@Test
|
||||
void rejectsTruncationCommitMismatchAndOversize() throws Exception
|
||||
{
|
||||
var truncated = fixture("source");
|
||||
truncated.get("trees/" + TREE + "?recursive=1").put("truncated", true);
|
||||
assertThrows(ScriptingException.class, () -> importer(truncated, new AtomicInteger()).importSnapshot(everything(), 42, REF));
|
||||
var mismatch = fixture("source");
|
||||
mismatch.get("commits/" + COMMIT).put("sha", TREE);
|
||||
assertThrows(ScriptingException.class, () -> importer(mismatch, new AtomicInteger()).importSnapshot(everything(), 42, REF));
|
||||
var oversized = fixture("source");
|
||||
oversized.get("trees/" + TREE + "?recursive=1").getJSONArray("tree").getJSONObject(0).put("size", 300000);
|
||||
assertThrows(ScriptingException.class, () -> importer(oversized, new AtomicInteger()).importSnapshot(everything(), 42, REF));
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Bytes must match their Git blob hash, declared size and strict UTF-8.
|
||||
***************************************************************************/
|
||||
@Test
|
||||
void rejectsChangedBlobAndEncoding() throws Exception
|
||||
{
|
||||
for(String field : List.of("content", "size", "encoding", "sha"))
|
||||
{
|
||||
var fixture = fixture("source");
|
||||
var blob = fixture.entrySet().stream().filter(entry -> entry.getKey().startsWith("blobs/")).findFirst().orElseThrow().getValue();
|
||||
blob.put(field, switch(field)
|
||||
{
|
||||
case "content" -> Base64.getEncoder().encodeToString("change".getBytes(StandardCharsets.UTF_8));
|
||||
case "size" -> 1;
|
||||
case "encoding" -> "utf-8";
|
||||
default -> COMMIT;
|
||||
});
|
||||
assertThrows(ScriptingException.class, () -> importer(fixture, new AtomicInteger()).importSnapshot(everything(), 42, REF));
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Managed repository denial prevents all HTTP traffic and cannot expose tokens.
|
||||
***************************************************************************/
|
||||
@Test
|
||||
void deniedAccessDoesNotFetch() throws Exception
|
||||
{
|
||||
var importer = new GitHubSourceImporter((actor, project, repository) ->
|
||||
{
|
||||
throw new ScriptingException(ScriptingException.Kind.DENIED, "Repository is not authorized");
|
||||
}, (path, token, maximum, timeout) ->
|
||||
{
|
||||
throw new AssertionError("Denied actor must not fetch");
|
||||
});
|
||||
assertThrows(ScriptingException.class, () -> importer.importSnapshot(everything(), 42, REF));
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Select an exact ordinary subtree; siblings are never downloaded or imported.
|
||||
***************************************************************************/
|
||||
@Test
|
||||
void selectsPinnedSubtreeAndRejectsDirectorySymlink() throws Exception
|
||||
{
|
||||
var fixture = fixture("source");
|
||||
String child = "c".repeat(40);
|
||||
var original = fixture.remove("trees/" + TREE + "?recursive=1").put("sha", child);
|
||||
fixture.put("trees/" + child + "?recursive=1", original);
|
||||
fixture.put("trees/" + TREE, new JSONObject().put("sha", TREE).put("truncated", false).put("tree", List.of(
|
||||
Map.of("path", "scripts", "type", "tree", "mode", "040000", "sha", child),
|
||||
Map.of("path", "README.md", "type", "blob", "mode", "100644", "sha", COMMIT))));
|
||||
var ref = new GitCommitRef("acme/scripts", COMMIT, "scripts");
|
||||
assertEquals(ref.origin(), importer(fixture, new AtomicInteger()).importSnapshot(everything(), 42, ref).origin());
|
||||
fixture.get("trees/" + TREE).getJSONArray("tree").getJSONObject(0).put("mode", "120000");
|
||||
assertThrows(ScriptingException.class, () -> importer(fixture, new AtomicInteger()).importSnapshot(everything(), 42, ref));
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Transport bounds apply while streaming, rather than after unbounded allocation.
|
||||
***************************************************************************/
|
||||
@Test
|
||||
void boundedBodyCancelsOversizedStream()
|
||||
{
|
||||
var body = new BoundedBody(2);
|
||||
AtomicInteger canceled = new AtomicInteger();
|
||||
body.onSubscribe(new Flow.Subscription()
|
||||
{
|
||||
/*******************************************************************
|
||||
** Fixture supplies chunks explicitly.
|
||||
*******************************************************************/
|
||||
@Override
|
||||
public void request(long count) {}
|
||||
|
||||
/*******************************************************************
|
||||
** Observe immediate cancellation.
|
||||
*******************************************************************/
|
||||
@Override
|
||||
public void cancel()
|
||||
{
|
||||
canceled.incrementAndGet();
|
||||
}
|
||||
});
|
||||
body.onNext(List.of(ByteBuffer.wrap(new byte[3])));
|
||||
assertTrue(body.getBody().toCompletableFuture().isCompletedExceptionally());
|
||||
assertEquals(1, canceled.get());
|
||||
var small = new BoundedBody(4);
|
||||
small.onSubscribe(new Flow.Subscription()
|
||||
{
|
||||
/*******************************************************************
|
||||
** Fixture supplies chunks explicitly.
|
||||
*******************************************************************/
|
||||
@Override
|
||||
public void request(long count) {}
|
||||
|
||||
/*******************************************************************
|
||||
** Successful fixture does not need cancellation.
|
||||
*******************************************************************/
|
||||
@Override
|
||||
public void cancel() {}
|
||||
});
|
||||
small.onNext(List.of(ByteBuffer.wrap(new byte[2])));
|
||||
small.onComplete();
|
||||
assertFalse(small.getBody().toCompletableFuture().isCompletedExceptionally());
|
||||
assertEquals(2, small.getBody().toCompletableFuture().join().length);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Fixture object responses use the actual commit/tree/blob API shapes.
|
||||
***************************************************************************/
|
||||
private Map<String, JSONObject> fixture(String content) throws Exception
|
||||
{
|
||||
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
|
||||
MessageDigest hash = MessageDigest.getInstance("SHA-1");
|
||||
hash.update(("blob " + bytes.length + "\0").getBytes(StandardCharsets.US_ASCII));
|
||||
String blob = SourceSnapshot.hex(hash.digest(bytes));
|
||||
Map<String, JSONObject> result = new HashMap<>();
|
||||
result.put("commits/" + COMMIT, new JSONObject().put("sha", COMMIT).put("tree", Map.of("sha", TREE)));
|
||||
result.put("trees/" + TREE + "?recursive=1", new JSONObject().put("sha", TREE).put("truncated", false).put("tree",
|
||||
List.of(Map.of("path", "src/main.ts", "mode", "100644", "type", "blob", "sha", blob, "size", bytes.length))));
|
||||
result.put("blobs/" + blob, new JSONObject().put("sha", blob).put("encoding", "base64").put("size", bytes.length)
|
||||
.put("content", Base64.getEncoder().encodeToString(bytes)));
|
||||
return (result);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
** Assert the trusted credential stays only at the HTTP boundary.
|
||||
***************************************************************************/
|
||||
private GitHubSourceImporter importer(Map<String, JSONObject> responses, AtomicInteger calls)
|
||||
{
|
||||
return (new GitHubSourceImporter((actor, project, repository) ->
|
||||
{
|
||||
assertEquals(42, project);
|
||||
assertEquals(REF.repository(), repository);
|
||||
calls.incrementAndGet();
|
||||
return ("fixture-credential");
|
||||
}, (path, token, maximum, timeout) ->
|
||||
{
|
||||
assertEquals("fixture-credential", token);
|
||||
assertTrue(timeout.toSeconds() <= 15);
|
||||
return (responses.get(path.substring(("/repos/" + REF.repository() + "/git/").length())).toString().getBytes(StandardCharsets.UTF_8));
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user