Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
187 lines
6.5 KiB
TypeScript
187 lines
6.5 KiB
TypeScript
import fs from "node:fs";
|
||||
|
|
import path from "node:path";
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
|
|
computeUserInitials,
|
|||
|
|
resolveYakNetWidgetAttributes,
|
|||
|
|
sanitizeYakNetWidgetUser,
|
|||
|
|
shouldSuppressUnauthenticatedSsoMessage,
|
|||
|
|
YAKNET_ACCOUNT_CDN_URL,
|
|||
|
|
YAKNET_AUTH_BASE,
|
|||
|
|
YAKNET_SSO_IFRAME_ID,
|
|||
|
|
} from "../../apps/web/src/lib/yaknetWidgetHelpers";
|
|||
|
||||
|
|
describe("YakNet SSO Cross-Subdomain Real-Time Session Synchronization", () => {
|
|||
|
|
it("validates incoming YAKNET_SSO_STATUS message payload structure", () => {
|
|||
|
|
const parseSsoMessage = (data: unknown) => {
|
|||
|
|
if (!data || typeof data !== "object") return null;
|
|||
|
|
const d = data as Record<string, unknown>;
|
|||
|
|
if (d.type !== "YAKNET_SSO_STATUS") return null;
|
|||
|
|
return {
|
|||
|
|
authenticated: Boolean(d.authenticated),
|
|||
|
|
user: d.user && typeof d.user === "object" ? (d.user as Record<string, unknown>) : null,
|
|||
|
|
};
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
const validPayload = {
|
|||
|
|
type: "YAKNET_SSO_STATUS",
|
|||
|
|
authenticated: true,
|
|||
|
|
user: {
|
|||
|
|
id: 42,
|
|||
|
|
name: "Yakup İpek",
|
|||
|
|
email: "[email protected]",
|
|||
|
|
avatar: "https://auth.yakhub.com.tr/avatars/42.png",
|
|||
|
|
},
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
const parsed = parseSsoMessage(validPayload);
|
|||
|
|
expect(parsed).not.toBeNull();
|
|||
|
|
expect(parsed?.authenticated).toBe(true);
|
|||
|
|
expect(parsed?.user?.name).toBe("Yakup İpek");
|
|||
|
|
expect(parsed?.user?.email).toBe("[email protected]");
|
|||
|
|
|
|||
|
|
// Invalid or unrelated message
|
|||
|
|
expect(parseSsoMessage({ type: "OTHER_EVENT" })).toBeNull();
|
|||
|
|
expect(parseSsoMessage(null)).toBeNull();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("formats cloud session sync request correctly for /cloud-api.php and /api/sync_session.php", () => {
|
|||
|
|
const buildSyncPayload = (ssoUser: { id?: number | string; name?: string; email?: string; avatar?: string | null }) => {
|
|||
|
|
const name = ssoUser.name?.trim() || "YakNet Kullanıcısı";
|
|||
|
|
const email = ssoUser.email?.trim() || "";
|
|||
|
|
const id = Number(ssoUser.id || 1);
|
|||
|
|
const avatar = ssoUser.avatar || `https://ui-avatars.com/api/?name=${encodeURIComponent(name)}&background=0284c7&color=fff`;
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
action: "sync_session",
|
|||
|
|
user: {
|
|||
|
|
id,
|
|||
|
|
name,
|
|||
|
|
email,
|
|||
|
|
avatar,
|
|||
|
|
},
|
|||
|
|
};
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
const payload = buildSyncPayload({
|
|||
|
|
id: 88,
|
|||
|
|
name: "Tasarımcı Öğrenci",
|
|||
|
|
email: "[email protected]",
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
expect(payload.action).toBe("sync_session");
|
|||
|
|
expect(payload.user.id).toBe(88);
|
|||
|
|
expect(payload.user.name).toBe("Tasarımcı Öğrenci");
|
|||
|
|
expect(payload.user.email).toBe("[email protected]");
|
|||
|
|
expect(payload.user.avatar).toContain("ui-avatars.com");
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("handles SSO logout and session clearing correctly", () => {
|
|||
|
|
let currentUser: { id: number; name: string } | null = { id: 10, name: "Aktif Kullanıcı" };
|
|||
|
|
let cloudProjectsCount = 5;
|
|||
|
|
|
|||
|
|
const handleSsoLogout = () => {
|
|||
|
|
currentUser = null;
|
|||
|
|
cloudProjectsCount = 0;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
handleSsoLogout();
|
|||
|
|
expect(currentUser).toBeNull();
|
|||
|
|
expect(cloudProjectsCount).toBe(0);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("ensures correct auth base URL for YakNet developer console SSO frame", () => {
|
|||
|
|
const ssoFrameUrl = `${YAKNET_AUTH_BASE}/sdk/sso-frame`;
|
|||
|
|
|
|||
|
|
expect(ssoFrameUrl).toBe("https://developer-console.yakhub.com.tr/sdk/sso-frame");
|
|||
|
|
expect(ssoFrameUrl.startsWith("https://developer-console.yakhub.com.tr")).toBe(true);
|
|||
|
|
});
|
|||
|
||||
|
|
it("omits authenticated attribute until session resolves to prevent login-button flash", () => {
|
|||
|
|
const unresolvedAttrs = resolveYakNetWidgetAttributes({
|
|||
|
|
user: null,
|
|||
|
|
sessionResolved: false,
|
|||
|
|
theme: "light",
|
|||
|
|
});
|
|||
|
|
expect(unresolvedAttrs.authenticated).toBeNull();
|
|||
|
|
expect(unresolvedAttrs["user-name"]).toBeNull();
|
|||
|
|
|
|||
|
|
const signedOutAttrs = resolveYakNetWidgetAttributes({
|
|||
|
|
user: null,
|
|||
|
|
sessionResolved: true,
|
|||
|
|
});
|
|||
|
|
expect(signedOutAttrs.authenticated).toBe("false");
|
|||
|
|
|
|||
|
|
const signedInAttrs = resolveYakNetWidgetAttributes({
|
|||
|
|
user: { id: 7, name: "Yakup İpek", email: "[email protected]" },
|
|||
|
|
sessionResolved: true,
|
|||
|
|
});
|
|||
|
|
expect(signedInAttrs.authenticated).toBe("true");
|
|||
|
|
expect(signedInAttrs["user-name"]).toBe("Yakup İpek");
|
|||
|
|
expect(signedInAttrs["user-email"]).toBe("[email protected]");
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("suppresses stale or cookie-less unauthenticated SSO frame messages safely", () => {
|
|||
|
|
expect(
|
|||
|
|
shouldSuppressUnauthenticatedSsoMessage({
|
|||
|
|
isDesktop: true,
|
|||
|
|
sessionResolved: true,
|
|||
|
|
hasAuthenticatedUser: true,
|
|||
|
|
ssoFrameHadAuthenticated: false,
|
|||
|
|
}),
|
|||
|
|
).toBe(true);
|
|||
|
|
|
|||
|
|
expect(
|
|||
|
|
shouldSuppressUnauthenticatedSsoMessage({
|
|||
|
|
isDesktop: false,
|
|||
|
|
sessionResolved: false,
|
|||
|
|
hasAuthenticatedUser: false,
|
|||
|
|
ssoFrameHadAuthenticated: false,
|
|||
|
|
}),
|
|||
|
|
).toBe(true);
|
|||
|
|
|
|||
|
|
expect(
|
|||
|
|
shouldSuppressUnauthenticatedSsoMessage({
|
|||
|
|
isDesktop: false,
|
|||
|
|
sessionResolved: true,
|
|||
|
|
hasAuthenticatedUser: true,
|
|||
|
|
ssoFrameHadAuthenticated: false,
|
|||
|
|
}),
|
|||
|
|
).toBe(true);
|
|||
|
|
|
|||
|
|
expect(
|
|||
|
|
shouldSuppressUnauthenticatedSsoMessage({
|
|||
|
|
isDesktop: false,
|
|||
|
|
sessionResolved: true,
|
|||
|
|
hasAuthenticatedUser: true,
|
|||
|
|
ssoFrameHadAuthenticated: true,
|
|||
|
|
}),
|
|||
|
|
).toBe(false);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("sanitizes YakNet widget users and computes avatar initials", () => {
|
|||
|
|
expect(sanitizeYakNetWidgetUser({ id: 0, name: "Invalid" })).toBeNull();
|
|||
|
|
expect(sanitizeYakNetWidgetUser({ id: 12, name: " Yakup İpek ", email: " [email protected] " })).toEqual({
|
|||
|
|
id: 12,
|
|||
|
|
name: "Yakup İpek",
|
|||
|
|
email: "[email protected]",
|
|||
|
|
avatar: null,
|
|||
|
|
auth_source: undefined,
|
|||
|
|
});
|
|||
|
|
expect(computeUserInitials("Yakup İpek")).toBe("Yİ");
|
|||
|
|
expect(computeUserInitials("Tekisim")).toBe("T");
|
|||
|
|
expect(computeUserInitials("")).toBe("YN");
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("keeps yaknet-account widget dynamically loaded from CDN without vendoring", () => {
|
|||
|
|
const repoRoot = path.resolve(__dirname, "../..");
|
|||
|
|
const layoutSource = fs.readFileSync(path.join(repoRoot, "apps/web/src/app/layout.tsx"), "utf8");
|
|||
|
|
const cloudBarSource = fs.readFileSync(path.join(repoRoot, "apps/web/src/components/snapcad/YakNetCloudBar.tsx"), "utf8");
|
|||
|
|
|
|||
|
|
expect(YAKNET_ACCOUNT_CDN_URL).toBe("https://cdnjs.yakhub.com.tr/ajax/libs/yaknet-account/latest/yaknet-account.js");
|
|||
|
|
expect(layoutSource).toContain("YAKNET_ACCOUNT_CDN_URL");
|
|||
|
|
expect(cloudBarSource).toContain("YAKNET_SSO_IFRAME_ID");
|
|||
|
|
expect(YAKNET_SSO_IFRAME_ID).toBe("yaknet-sso-iframe-instance");
|
|||
|
|
expect(fs.existsSync(path.join(repoRoot, "apps/web/public/yaknet-account.js"))).toBe(false);
|
|||
|
|
});
|
|||
});
|